home *** CD-ROM | disk | FTP | other *** search
- import java.applet.Applet;
- import java.awt.Choice;
- import java.awt.Color;
- import java.awt.Component;
- import java.awt.Container;
- import java.awt.Event;
- import java.awt.Graphics;
- import java.util.Vector;
-
- public class SimpleDraw extends Applet {
- Vector drawnShapes;
- Choice shapeChoice;
- Choice colorChoice;
-
- public void init() {
- this.drawnShapes = new Vector();
- this.shapeChoice = new Choice();
- this.shapeChoice.addItem("Circle");
- this.shapeChoice.addItem("Square");
- ((Container)this).add(this.shapeChoice);
- this.colorChoice = new Choice();
- this.colorChoice.addItem("Red");
- this.colorChoice.addItem("Green");
- this.colorChoice.addItem("Blue");
- ((Container)this).add(this.colorChoice);
- }
-
- public void paint(Graphics var1) {
- int var3 = this.drawnShapes.size();
-
- for(int var4 = 0; var4 < var3; ++var4) {
- Shape var2 = (Shape)this.drawnShapes.elementAt(var4);
- var2.draw(var1);
- }
-
- }
-
- public boolean mouseUp(Event var1, int var2, int var3) {
- String var5 = this.shapeChoice.getSelectedItem();
- String var6 = this.colorChoice.getSelectedItem();
- Object var4;
- if (var5.equals("Circle")) {
- var4 = new Circle();
- } else {
- var4 = new Square();
- }
-
- if (var6.equals("Red")) {
- ((Shape)var4).color = Color.red;
- } else if (var6.equals("Green")) {
- ((Shape)var4).color = Color.green;
- } else {
- ((Shape)var4).color = Color.blue;
- }
-
- ((Shape)var4).x = var2;
- ((Shape)var4).y = var3;
- this.drawnShapes.addElement(var4);
- ((Component)this).repaint();
- return true;
- }
- }
-