import java.awt.*; public class ColorsWindow extends Frame { MagControls outerparent; MagPuz super_parent; Choice bgmagcontrols, bgmagpuz, fgmagpuz, box, outline, numbers; ColorsWindow(MagControls target) { super("Colors"); this.outerparent = target; this.super_parent = target.outerparent; //Setup Layout setLayout(new FlowLayout(FlowLayout.LEFT)); //Setup Choice Menus bgmagcontrols = new Choice(); bgmagpuz = new Choice(); fgmagpuz = new Choice(); box = new Choice(); outline = new Choice(); numbers = new Choice(); add_items(bgmagcontrols); //Add colors to the Choice Menu add_items(bgmagpuz); //Add colors to the Choice Menu add_items(fgmagpuz); //Add colors to the Choice Menu add_items(box); add_items(outline); add_items(numbers); bgmagcontrols.select("White"); bgmagpuz.select("White"); fgmagpuz.select("Black"); box.select("Yellow"); outline.select("Red"); numbers.select("Black"); //Add Labels and Menus to Control Frame add(new Label("BG Control: ")); add(bgmagcontrols); add(new Label("FG Puzzle: ")); add(fgmagpuz); add(new Label("BG Puzzle: ")); add(bgmagpuz); add(new Label("Numbers: ")); add(numbers); add(new Label("Box: ")); add(box); add(new Label("Outline: ")); add(outline); } //Add colors to a Choice Menu public void add_items(Choice name) { name.addItem("Black"); name.addItem("Red"); name.addItem("Green"); name.addItem("Blue"); name.addItem("White"); name.addItem("Yellow"); } //Handle Clicks. public boolean action(Event evt, Object arg) { if (evt.target instanceof Choice) { String col = (String)arg; Color theColor = Color.black; if (col.equals("Blue")) theColor = Color.blue; else if (col.equals("Red")) theColor = Color.red; else if (col.equals("Green")) theColor = Color.green; else if (col.equals("Black")) theColor = Color.black; else if (col.equals("White")) theColor = Color.white; else if (col.equals("Yellow")) theColor = Color.yellow; //Check which color to update and call color_update. if (evt.target == bgmagcontrols) outerparent.updatecolor("bg", theColor); else if (evt.target == fgmagpuz) super_parent.magcan.updatecolor ("fg", theColor); else if (evt.target == bgmagpuz) super_parent.magcan.updatecolor ("bg", theColor); else if (evt.target == box) super_parent.magcan.updatecolor ("box", theColor); else if (evt.target == outline) super_parent.magcan.updatecolor ("outline", theColor); else if (evt.target == numbers) super_parent.magcan.updatecolor ("numbers", theColor); } return true; } }