Basic HTML version of Foils prepared 7 Sept 1997

Foil 19 The Simplest Java Applet: Hello, World!

From Introduction to Java to be used in (Scientific) Computing Basic Simulation Track for Computational Science CPS615 -- Fall Semester 97. by Geoffrey C. Fox, Nancy McCracken


Java applets are part of the class hierarchy that can call methods to display on a screen (within the browser window). This example defines the public method paint in this class and calls a method drawString defined in the class Graphics.
Import java.awt.Graphics;
public class HelloWorldApplet extends java.applet.Applet
{ public void paint(Graphics g)
{ g.drawString("Hello World!",5,25); }
}
The paint method displays a graphics object on the screen
one of the standard methods that replaces main for applets
The import statement is similar to an include and makes all the method
names in the Graphics class in the awt package available
Puts this as a subclass of Applet
Drawstring is one of many
available display methods



© 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 Sun Nov 29 1998