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


1 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.
2 Import java.awt.Graphics;
3 public class HelloWorldApplet extends java.applet.Applet
4 { public void paint(Graphics g)
5 { g.drawString("Hello World!",5,25); }
6 }
7 The paint method displays a graphics object on the screen
8 one of the standard methods that replaces main for applets
9 The import statement is similar to an include and makes all the method
10 names in the Graphics class in the awt package available
11 Puts this as a subclass of Applet
12 Drawstring is one of many
13 available display methods

in Table To:


© 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