1 /* Drawing Simple Shapes - Nancy McCracken */ 2 3 import java.awt.*; 4 5 public class Mushroom extends java.applet.Applet 6 { 7 public void paint(Graphics g) 8 { 9 setBackground(Color.white); 10 11 // x and y origins of mushroom 12 int ox = 20; 13 int oy = 100; 14 15 g.setColor(Color.yellow); 16 g.fillRect (ox+30, oy+40, 20, 40); 17 18 // drawArc (x, y, width, height, startangle, arcangle); 19 g.fillArc (ox, oy, 80, 80, 180, -180); 20 21 ox = 120; 22 oy = 20; 23 g.setColor (Color.green); 24 25 // arrays for x and y points of the polygon 26 int xpoints[] = 27 {40, 40, 0, 20, 10, 30, 20, 50, 80, 70, 90, 80, 100, 60, 60}; 28 int ypoints[] = 29 {160,120,120,80, 80, 40, 40, 0, 40, 40, 80, 80, 120,120, 160}; 30 for (int i = 0; i < xpoints.length; i++) 31 { xpoints[i] += ox; 32 ypoints[i] += oy; 33 } 34 g.fillPolygon(xpoints, ypoints, 15); 35 36 g.setColor (Color.black); 37 g.drawString("Mushroom and Tree", 60, 220); 38 } 39 } 40