
7.12 Graphical Objects 419
does not have any instance variables and so doesn’t need to perform any
initialization, then the init method is optional.
We call the Astronaut’s draw method in the applet’s paint method (line 23),
passing to draw the Graphics object reference g that was passed to paint.
The applet window is shown in Figure 7.9.
1 /* Astronaut client
2 Anderson, Franceschi
3 */
4
5 import javax.swing.JApplet;
6 import java.awt.Graphics;
7
8 public class AstronautClient extends JApplet
9 {
10 // instance variable is an Astronaut
11 private Astronaut astro;
12
13 public void init()
14 {
15 // instantiate the Astronaut object
16 astro = new Astronaut(