import java.applet.Applet; import java.awt.*; import java.awt.event.*; import java.util.Vector; import m865.shapepack.Shape; import m865.shapepack.ShapeFactory; /** * This app/applet interactively paints various shapes. It uses a ShapeFactory * object to provide the list of possible shapes and two methods to create specified * shapes from that list. When run as an application there is a simple one line * modification that enables a subclass of ShapeFactory to be used which can include * additional shapes. The default ShapeFactory includes only rectangles, ellipses, * and squares. *

* This applet paints a shape of the color you've chosen wherever you click. * This applet keeps a list of the shapes you've drawn * and paints all the shapes in the list when it repaints. *

* Java's classes: Applet (applet) *

*

* Custom classes: SimpleDraw *

* @author Daniel D. Warner * * @version 2.0 09/01/05 * */ public class SimpleDraw3 extends Applet { /** * */ private static final long serialVersionUID = 1L; /** * default Width for new shapes */ public static final int defaultWidth = 150; /** * default Height for new shapes */ public static final int defaultHeight = 75; /** * The factory for cataloging and creating the shapes */ ShapeFactory factory; /** * The list of shapes to be drawn */ Vector drawnShapes; /** * The shape selector */ Choice shapeChoice; /** * The color selector */ Choice colorChoice; /** * The button for clearing the list of shapes */ Button clearButton; /** * The constructor which enables the shape factory * to be specified by the main method. */ public SimpleDraw3(ShapeFactory factory) { this.factory = factory; } /** * Default constructor uses MyFactory. */ public SimpleDraw3() { // this(new ShapeFactory()); this(new MyFactory()); } /** * Initializes the Graphical User Interface. */ public void init() { drawnShapes = new Vector(); shapeChoice = new Choice(); String[] catalog = factory.getTheList(); for (int k=0; k