A Simple Java Applet

import java.awt.*;
import java.applet.Applet;

public class HelloWorld extends Applet {
	public void paint(Graphics g) {
		g.drawString("Hello World!", 25, 25);
	}
}

The source code.

Important Note: the name of the program must have the same name as the public class followed by a .java extension, in this case HelloWorld.java.

To compile this program, type:

	javac HelloWorld.java

To see the applet, you need to embed the applet within an HTML file. For now you can use the following HTML file (example.html):

<APPLET code="HelloWorld.class" width=300 height=200>
</APPLET>
To see the applet, you must load the example.html file in your browser or type:
	appletviewer example.html
from the command line to invoke the appletviewer.

Next lecture, you will learn the HTML syntax for Java applets.


Back to lab1