10 package org.bitstorm.gameoflife;
12 import java.awt.Button;
13 import java.awt.Choice;
14 import java.awt.Label;
15 import java.awt.Panel;
16 import java.awt.event.ActionEvent;
17 import java.awt.event.ActionListener;
18 import java.awt.event.ItemEvent;
19 import java.awt.event.ItemListener;
20 import java.util.Enumeration;
21 import java.util.Vector;
38 public static final String
SLOW =
"Slow";
39 public static final String
FAST =
"Fast";
40 public static final String
HYPER =
"Hyper";
41 public static final String
BIG =
"Big";
42 public static final String
MEDIUM =
"Medium";
43 public static final String
SMALL =
"Small";
57 listeners =
new Vector();
60 shapesChoice =
new Choice();
64 for (
int i = 0; i < shapes.length; i++ )
65 shapesChoice.addItem( shapes[i].
getName() );
68 shapesChoice.addItemListener(
70 public void itemStateChanged(ItemEvent e) {
77 Choice speedChoice =
new Choice();
80 speedChoice.addItem(SLOW);
81 speedChoice.addItem(FAST);
82 speedChoice.addItem(HYPER);
85 speedChoice.addItemListener(
87 public void itemStateChanged(ItemEvent e) {
88 String arg = (String) e.getItem();
91 else if (FAST.equals(arg))
93 else if (HYPER.equals(arg))
100 zoomChoice =
new Choice();
103 zoomChoice.addItem(BIG);
104 zoomChoice.addItem(MEDIUM);
105 zoomChoice.addItem(SMALL);
108 zoomChoice.addItemListener(
110 public void itemStateChanged(ItemEvent e) {
111 String arg = (String) e.getItem();
114 else if (MEDIUM.equals(arg))
116 else if (SMALL.equals(arg))
123 genLabel =
new Label(genLabelText+
" ");
126 startstopButton =
new Button(startLabelText);
129 startstopButton.addActionListener(
130 new ActionListener() {
131 public void actionPerformed(ActionEvent e) {
138 nextButton =
new Button(nextLabelText);
141 nextButton.addActionListener(
142 new ActionListener() {
143 public void actionPerformed(ActionEvent e) {
150 this.add(shapesChoice);
151 this.add(nextButton);
152 this.add(startstopButton);
153 this.add(speedChoice);
154 this.add(zoomChoice);
165 listeners.addElement( listener );
173 listeners.removeElement( listener );
181 genLabel.setText(genLabelText + generations +
" ");
188 startstopButton.setLabel(stopLabelText);
189 nextButton.disable();
190 shapesChoice.disable();
197 startstopButton.setLabel(startLabelText);
199 shapesChoice.enable();
208 for ( Enumeration e = listeners.elements(); e.hasMoreElements(); )
218 for ( Enumeration e = listeners.elements(); e.hasMoreElements(); )
228 for ( Enumeration e = listeners.elements(); e.hasMoreElements(); )
238 for ( Enumeration e = listeners.elements(); e.hasMoreElements(); )
248 for ( Enumeration e = listeners.elements(); e.hasMoreElements(); )
257 zoomChoice.select(n);
void startStopButtonClicked()
static final int SIZE_BIG
final String startLabelText
static final int SIZE_MEDIUM
void removeGameOfLifeControlsListener(GameOfLifeControlsListener listener)
static Shape[] getShapes()
static GameOfLifeControlsEvent getShapeSelectedEvent(Object source, String shapeName)
static GameOfLifeControlsEvent getSpeedChangedEvent(Object source, int speed)
void setGeneration(int generations)
static final String MEDIUM
static final String HYPER
void zoomChanged(int zoom)
final String genLabelText
final String nextLabelText
static final String SMALL
static GameOfLifeControlsEvent getZoomChangedEvent(Object source, int zoom)
void addGameOfLifeControlsListener(GameOfLifeControlsListener listener)
static final int SIZE_SMALL
final String stopLabelText
void speedChanged(int speed)
void shapeSelected(String shapeName)