
When drawing a figure
using graphics,specify
coordinates as offsets from
a starting (x,y) coordinate.
SOFTWARE
ENGINEERING TIP
192 CHAPTER 4 Introduction to Applets and Graphics
42
43 // flag
44 g.drawLine( sX + 195, sY + 80, sX + 195 , sY );
45 g.drawRect( sX + 195, sY, 75, 45 );
46 g.drawRect( sX + 195, sY, 30, 25 );
47
48 // caption
49 g.drawString( “One small step for man. . .”,
50 sX + 25, sY + 270 );
51 }
52 }
EXAMPLE 4.8 An Applet that Draws an Astronaut
When the applet in Example 4.8 runs, our astronaut will look like the one
in Figure 4.8.
To draw our astronaut, we used rectangles for the body, arms, legs, and flag;
lines for the nose and the flag’s stick; ...