Thursday, 17 May 2007

Applets and Graphics

CHAPTER 36—Applets
An applet usually is used as part of a Web page. The applet is responsible for the graphical components and user interaction in a rectangular section of the Web browser's screen. Applets are typically used for user interaction with the Web page.

An applet is an object that is used by another program, typically a Web browser. The Web browser is the application program and (at least conceptually) holds the main() method. The applet part of a Web page provides services (methods) to the browser when the browser asks for them.

To access these definitions, your program should import javax.applet.JApplet and java.awt.*.

drawString( String str, int x, int y)
str — a String to place into the drawing area
x — horizontal distance in pixels from the left edge
y — vertical distance in pixels from the top edge

Distance is measured in pixels. A pixel is one of the graph paper squares that the video screen has been (conceptually) divided into. If your monitor is set to a resolution of 800 by 600, then the whole screen is divided into 800 horizontal squares and 600 vertical squares. An applet will usually cover only part of that area, perhaps an area 300 horizontal by 150 vertical. It is the responsibility of the graphics card and its driver to implement this idea of graph paper on the actual electronics of you computer system.

An applet does not have a main() method and so cannot be started as an application.

appletviewer displays only the applet part of an HTML file. The other parts (if any) are omitted.
Appletviewer is run from the command prompt window. If javac and java have been working, then the following should work:

C:\>appletviewer AnotherHello.html

mark the START of a "html" file. These should be the FIRST characters in the file.
mark the END of a "html" file. These should be the LAST characters in the file.
mark the start of the head of the file. The head of the file contains descriptions and declarations that are not supposed to be directly visible on the Web page.
mark the end of the head of the file.
give a title to the entire page (the Web browser can use the title for whatever purpose it wishes.) This should be in the head section of the page. <br /> end of the title.
mark the start of the body of the file. The body of the file is the main part that is visible on the monitor screen.
mark the end of the body of the file.

a horizontal rule: a line completely across the screen. There is no matching tag.


class Circle
{
// variables



// constructors


// methods


}

No comments: