Java Reference
In-Depth Information
The class that contains this method ( HelloWorld , in this example) does not
need to be any particular name, but it does need to be public. This class must
be of the sort that extends , or inherits, from a class named Applet .
The statement import java.applet.Applet; at the beginning of the class tells
the Java compiler where to find the Applet class.
The internal name of the class (in the source program) and the external name
of the class (the HelloWorld.class file built by the compiler) must be the same.
A Java program run in this manner expects to have a GUI environment avail-
able to it. It also expects to be able to write to a logical file known as standard
out and to read from standard in.
Standard out and standard in are not well defined for these types of programs.
The statement g.drawString("Hello World!", 5, 25); writes to the graphical
environment. It performs the drawString method in the Graphics class. This
method accepts a String input parameter and writes it to the graphical envi-
ronment. There are additional controls to this method. In the example, I've
specified the starting position in the graphical window to place the String .
Think of it as analogous to this type of COBOL statement, extended with the
ability to position the text anywhere on the screen:
DISPLAY "Hello World!" AT COLUMN 5 LINE 25
The statement import java.awt.Graphics; at the beginning of the class tells the
Java compiler where to find the Graphics class.
Subsequent calls to drawString write text to the specified place in the graphical
window.
g.drawString("Hello Applet World!", 5, 25);
g.drawString("Hello Applet World!", 5, 25);
g.drawString("Hello Applet World!", 5, 25);
g.drawString("Hello Applet World!", 6, 25);
g.drawString("Hello Applet World!", 5, 25);
g.drawString("Hello Applet World!", 5, 35);
Search WWH ::




Custom Search