/* Copyright (C) 2002 J. M. Spivey */ import java.awt.*; import java.awt.event.*; /** Main class for the LightsOut application */ public class LightsOut extends DemoFrame { private Panel controls = new Panel(new GridLayout(3, 1)); private Panel panel1 = new Panel(); private Panel panel2 = new Panel(); private Label messageBar = new Label(); private LightsBoard board = new LightsBoard(messageBar); private CheckboxGroup modegrp = new CheckboxGroup(); private Checkbox playmode; private Button addButton(String name, Panel panel, ActionListener action) { Button b = new Button(name); b.addActionListener(action); panel.add(b); return b; } private void addModeCheckbox(String label, final int mode) { Checkbox b = new Checkbox(label, modegrp, mode == LightsBoard.PLAY); b.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { if (e.getStateChange() == ItemEvent.SELECTED) board.setMode(mode); } }); panel1.add(b); } public LightsOut() { super("Lights Out"); add(board, "Center"); add(controls, "South"); controls.add(messageBar); controls.add(panel1); controls.add(panel2); addModeCheckbox("Play", LightsBoard.PLAY); addModeCheckbox("Setup", LightsBoard.SETUP); addButton("Random 5", panel2, new ActionListener() { public void actionPerformed(ActionEvent e) { board.setRandom(5); } }); addButton("Random 10", panel2, new ActionListener() { public void actionPerformed(ActionEvent e) { board.setRandom(10); } }); addButton("Blank", panel2, new ActionListener() { public void actionPerformed(ActionEvent e) { board.setBlank(); } }); addButton("Solve", panel2, new ActionListener() { public void actionPerformed(ActionEvent e) { board.showSolution(); } }); addButton("Quit", panel2, new ActionListener() { public void actionPerformed(ActionEvent e) { die(); } }); pack(); } public static void main(String args[]) { LightsOut frame = new LightsOut(); frame.setVisible(true); } }