home *** CD-ROM | disk | FTP | other *** search
/ Inside Dreamweaver 4 / IDW4.ISO / pc / Projects / ch20 / java / SimpleDraw / SimpleDraw.class (.txt) < prev    next >
Encoding:
Java Class File  |  2000-04-03  |  1.6 KB  |  63 lines

  1. import java.applet.Applet;
  2. import java.awt.Choice;
  3. import java.awt.Color;
  4. import java.awt.Component;
  5. import java.awt.Container;
  6. import java.awt.Event;
  7. import java.awt.Graphics;
  8. import java.util.Vector;
  9.  
  10. public class SimpleDraw extends Applet {
  11.    Vector drawnShapes;
  12.    Choice shapeChoice;
  13.    Choice colorChoice;
  14.  
  15.    public void init() {
  16.       this.drawnShapes = new Vector();
  17.       this.shapeChoice = new Choice();
  18.       this.shapeChoice.addItem("Circle");
  19.       this.shapeChoice.addItem("Square");
  20.       ((Container)this).add(this.shapeChoice);
  21.       this.colorChoice = new Choice();
  22.       this.colorChoice.addItem("Red");
  23.       this.colorChoice.addItem("Green");
  24.       this.colorChoice.addItem("Blue");
  25.       ((Container)this).add(this.colorChoice);
  26.    }
  27.  
  28.    public void paint(Graphics var1) {
  29.       int var3 = this.drawnShapes.size();
  30.  
  31.       for(int var4 = 0; var4 < var3; ++var4) {
  32.          Shape var2 = (Shape)this.drawnShapes.elementAt(var4);
  33.          var2.draw(var1);
  34.       }
  35.  
  36.    }
  37.  
  38.    public boolean mouseUp(Event var1, int var2, int var3) {
  39.       String var5 = this.shapeChoice.getSelectedItem();
  40.       String var6 = this.colorChoice.getSelectedItem();
  41.       Object var4;
  42.       if (var5.equals("Circle")) {
  43.          var4 = new Circle();
  44.       } else {
  45.          var4 = new Square();
  46.       }
  47.  
  48.       if (var6.equals("Red")) {
  49.          ((Shape)var4).color = Color.red;
  50.       } else if (var6.equals("Green")) {
  51.          ((Shape)var4).color = Color.green;
  52.       } else {
  53.          ((Shape)var4).color = Color.blue;
  54.       }
  55.  
  56.       ((Shape)var4).x = var2;
  57.       ((Shape)var4).y = var3;
  58.       this.drawnShapes.addElement(var4);
  59.       ((Component)this).repaint();
  60.       return true;
  61.    }
  62. }
  63.