Java Reference
In-Depth Information
Congratulations! You should be proud of your first Java program. It is full of
potential.
Experiment with the program a little bit in this environment. You can make
the changes in the text editor you have chosen. Compile it by typing javac Hello-
World.java in the command window. After your program is compiled, you can exe-
cute it from the MS-DOS command window by typing java HelloWorld .
Change the message from “Hello World!” to “Watson come here!”
What happens if you add a second System.out.println statement to your
program?
A PPLETS WITH SDK
Now you'll write your first Java applet in this environment and run it in the Applet
viewer.
1. Using either Windows Explorer or a DOS command, create a new direc-
tory (or folder, in Explorer terminology) called “applet” in the java4cobol
directory. Your applet files will be stored in this directory.
2. Using a text editor, create a Java source file named HelloWorld.java in this
directory. The source file should contain these statements:
import java.applet.Applet;
import java.awt.Graphics;
public class HelloWorld extends Applet {
public void paint(Graphics g)
{
g.drawString("Hello Applet World!", 5, 25);
}
}
3. In the DOS command window, change the current directory to your applet
directory:
cd c:\java4cobol\applet
4. Compile your applet using the javac compiler:
javac HelloWorld.java
Search WWH ::




Custom Search