Basic HTML version of Foils prepared September 1 99

Foil 12 The Simplest Java Applet: Hello, World!

From Introduction to Java Language and Applets CPS406/606 Fall Semester 1999 -- September 2 99. by Nancy J. McCracken, Geoffrey C. Fox

The HelloWorld Applet for Foil 12
Java applets are part of the class hierarchy that can call methods to display on a screen (within the browser window). One way to draw on the screen is to call the method drawString from the standard method paint.
import java.awt.Graphics;
public class HelloApplet extends java.applet.Applet
{ public void paint (Graphics g)
{ g.drawString("Hello World!", 5, 25);
}
}
The import statement (similar to an include) allows the use of methods from the Graphics class .
The paint method displays a graphics object on the screen - one of the standard methods that takes the place of main for applets.
Puts this as a subclass of Applet.



© Northeast Parallel Architectures Center, Syracuse University, npac@npac.syr.edu

If you have any comments about this server, send e-mail to webmaster@npac.syr.edu.

Page produced by wwwfoil on Wed Sep 1 1999