home *** CD-ROM | disk | FTP | other *** search
/ Java by Example / jbecd.bin / JBE-CD / NTUsers / JBECODE.ZIP / JavaByExample / chap16 / ShapeApplet.java < prev   
Text File  |  1996-02-20  |  1KB  |  57 lines

  1. import java.awt.*;
  2. import java.applet.*;
  3.  
  4. public class ShapeApplet extends Applet
  5. {
  6.     int shape;
  7.     Button button;
  8.  
  9.     public void init()
  10.     {
  11.         shape = 0;
  12.         button = new Button("Next Shape");
  13.         add(button);
  14.     }
  15.  
  16.     public void paint(Graphics g)
  17.     {
  18.         int x[] = {35, 150, 60, 140, 60, 150, 35};
  19.         int y[] = {50, 80, 110, 140, 170, 200, 230};
  20.         int numPts = 7;
  21.  
  22.         switch(shape)
  23.         {
  24.             case 0:
  25.                 g.drawLine(35, 50, 160, 230);
  26.                 break;
  27.             case 1:
  28.                 g.drawRect(35, 50, 125, 180);
  29.                 break;
  30.             case 2:
  31.                 g.drawRoundRect(35, 50, 125, 180, 15, 15);
  32.                 break;
  33.             case 3:
  34.                 g.drawOval(35, 50, 125, 180);
  35.                 break;
  36.             case 4:
  37.                 g.drawArc(35, 50, 125, 180, 90, 180);
  38.                 break;
  39.             case 5:
  40.                 g.drawPolygon(x, y, numPts);
  41.                 break;
  42.             case 6:
  43.                 g.fillPolygon(x, y, numPts);
  44.                 break;
  45.         }
  46.     }
  47.  
  48.     public boolean action(Event event, Object arg)
  49.     {
  50.         ++shape;
  51.         if (shape == 7)
  52.             shape = 0;
  53.         repaint();
  54.         return true;
  55.     }
  56. }
  57.