ControlPanepublic class ControlPane extends JPanel implements ActionListener, FocusListener
Fields Summary |
---|
protected static final String | go | protected static final String | stop | protected static final String | delayString | protected static final String | countDownString | protected static final String | maxPlayersString | protected static final String | maxCardsString | protected static final String | hostLabelString | protected JTextField | delayField | protected JTextField | countDownField | protected JTextField | maxPlayersField | protected JTextField | maxCardsField | protected JButton | goButton | protected JButton | stopButton | private RingMaster | ringMaster | private GameParameters | gameParameters | private GamesThread | gamesThread |
Constructors Summary |
---|
public ControlPane(String hostname, RingMaster ringMaster)
super(false);
this.ringMaster = ringMaster;
this.gameParameters = ringMaster.getGameParameters();
// create the properties fields
JLabel delayLabel = new JLabel(delayString, JLabel.RIGHT);
delayField = new JTextField(new
Long(gameParameters.getDelay()/Constants.ONE_SECOND).toString());
delayField.setActionCommand(delayString);
JLabel countDownLabel = new JLabel(countDownString, JLabel.RIGHT);
countDownField = new JTextField(new
Long(gameParameters.getCountDown()/Constants.ONE_SECOND).toString());
countDownField.setActionCommand(countDownString);
JLabel maxPlayersLabel = new JLabel(maxPlayersString, JLabel.RIGHT);
maxPlayersField = new JTextField(new
Integer(gameParameters.getMaxPlayers()).toString());
maxPlayersField.setActionCommand(maxPlayersString);
JLabel maxCardsLabel = new JLabel(maxCardsString, JLabel.RIGHT);
maxCardsField = new JTextField(new
Integer(gameParameters.getMaxCards()).toString());
maxCardsField.setActionCommand(maxCardsString);
JLabel hostLabel = new JLabel(hostLabelString, JLabel.RIGHT);
JLabel hostNameLabel = new JLabel(hostname);
// create the go and stop buttons
goButton = new JButton(go);
goButton.setMnemonic('g");
goButton.setActionCommand(go);
stopButton = new JButton(stop);
stopButton.setMnemonic('s");
stopButton.setActionCommand(stop);
stopButton.setEnabled(false);
// Register the listeners
delayField.addActionListener(this);
delayField.addFocusListener(this);
countDownField.addActionListener(this);
countDownField.addFocusListener(this);
maxPlayersField.addActionListener(this);
maxPlayersField.addFocusListener(this);
maxCardsField.addActionListener(this);
maxCardsField.addFocusListener(this);
goButton.addActionListener(this);
stopButton.addActionListener(this);
// Do the layout.
JPanel parameterPane = new JPanel(false);
parameterPane.setBorder(BorderFactory.createTitledBorder(
BINGO.controlPaneTitle));
GridBagLayout gridbag = new GridBagLayout();
parameterPane.setLayout(gridbag);
// many rows
Utilities.addParameterRow(parameterPane,
delayLabel,
delayField);
Utilities.addParameterRow(parameterPane,
countDownLabel,
countDownField);
Utilities.addParameterRow(parameterPane,
maxPlayersLabel,
maxPlayersField);
Utilities.addParameterRow(parameterPane,
maxCardsLabel,
maxCardsField);
Utilities.addParameterRow(parameterPane,
hostLabel,
hostNameLabel);
JComponent[] compList = new JComponent[2];
compList[0] = goButton;
compList[1] = stopButton;
Box buttonBox = Utilities.makeEvenlySpacedBox(compList);
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
add(parameterPane);
add(Box.createRigidArea(new Dimension(20, 20)));
add(buttonBox);
add(Box.createRigidArea(new Dimension(20, 20)));
|
Methods Summary |
---|
public void | actionPerformed(java.awt.event.ActionEvent e)
if (e.getActionCommand() == go) {
if (gamesThread == null) {
gamesThread = new GamesThread(ringMaster);
gamesThread.start();
goButton.setEnabled(false);
stopButton.setEnabled(true);
}
} else if (e.getActionCommand() == stop) {
if (gamesThread != null) {
gamesThread.noMoreGames();
gamesThread = null;
stopButton.setEnabled(false);
goButton.setEnabled(false);
}
} else if (e.getActionCommand() == delayString) {
gameParameters.setDelay((Long.parseLong(delayField.getText()))*Constants.ONE_SECOND);
} else if (e.getActionCommand() == countDownString) {
gameParameters.setCountDown((Long.parseLong(countDownField.getText()))*Constants.ONE_SECOND);
} else if (e.getActionCommand() == maxPlayersString) {
gameParameters.setMaxPlayers(Integer.parseInt(maxPlayersField.getText()));
} else if (e.getActionCommand() == maxCardsString) {
gameParameters.setMaxCards(Integer.parseInt(maxCardsField.getText()));
}
| public void | focusGained(java.awt.event.FocusEvent e)
| public void | focusLost(java.awt.event.FocusEvent e)
//when a field loses the focus, generate an action event
JTextField source;
ActionEvent event;
source = (JTextField)(e.getComponent());
source.postActionEvent();
//event = new ActionEvent(source,
//ActionEvent.ACTION_PERFORMED,
//source.getCommand());
//actionPerformed(new
//ACK! There's no JTextField getActionCommand or performAction!
//is postActionEvent the same as the latter?
| public java.awt.Dimension | getMaximumSize()
Dimension d = getPreferredSize();
d.width = Short.MAX_VALUE;
return d;
|
|