import java.applet.*; import java.awt.*; /** *This class implements the control strip. *It captures the users changes to the shape *choice controls, and calls upon the appropriate *function in the whiteBoard class to acknowledge *the changes. *It also implements the reset button which clears *the drawing area on the whiteBoard object */ public class controlStrip extends Panel { whiteBoard target; // declare the choice controls Choice shapeChoice, colorChoice, fillChoice; Button resetButton; /** * controlStrip class constructor, * it initializes the controlStrip object */ public controlStrip(whiteBoard target) { // sets the target to the whiteBoard object this.target = target; // sets the font setFont(new Font("Helvetica", Font.BOLD, 15)); // populates the color pull-down menu colorChoice = new Choice(); colorChoice.addItem("Green"); colorChoice.addItem("Blue"); colorChoice.addItem("Yellow"); // populates the shape pull-down menu shapeChoice = new Choice(); shapeChoice.addItem("Line"); shapeChoice.addItem("Rectangle"); shapeChoice.addItem("Ellipse"); // populates the style pull-down menu fillChoice = new Choice(); fillChoice.addItem("Filled"); fillChoice.addItem("Hollow"); resetButton = new Button("Reset"); // add the actual controls to the stripControl panel add(shapeChoice); add(colorChoice); add(fillChoice); add(resetButton); } /*-----------------------------------------------*/ /** This function detects the controls' changes * in the controlStrip panel. According to the * change, the appropriate function in the * whiteBoard class is called (using the target * variable set when initializing the class) * to implement the change. */ /*-----------------------------------------------*/ public boolean action(Event event, Object object) { if (event.target == shapeChoice) { // The user changed the actual shape // determine selected shape String selection = shapeChoice.getSelectedItem(); // change the shape on the whiteboard accordingly target.changeShape(selection); return(true); } else if (event.target == colorChoice) { // The user changed the color // determine selected color String selection = colorChoice.getSelectedItem(); // change the color on the whiteboard accordingly target.changeColor(selection); return(true); } else if (event.target == fillChoice) { // The user changed the fill style // determine selected fill style String selection = fillChoice.getSelectedItem(); // change the style on the whiteboard accordingly target.changeFillColor(selection); return(true); } else if (event.target == resetButton) { // The user cleared the drawing area // clear all the drawing area target.clearDrawingArea(); return(true); }else return(false); } }