1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
|
/*
* Created on 20 oct. 2004
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
package game;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
/**
* @author Ender
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public class ChoiceDialog extends JDialog
/*implements ActionListener, ItemListener */{
private JPanel panel1, panel2, panel3;
private final int numButtons = 3;
private JRadioButton[] radioButtons = new JRadioButton[numButtons];
private final ButtonGroup group = new ButtonGroup();
private final JLabel label = new JLabel("Choose the game settings:\n");
private JButton buttonOK;
private JButton buttonCancel;
private int choice;
private final String oneP_oneCCommand = "onePlayer_oneComputer";
private final String twoP_oneCCommand = "twoPlayers_oneComputer";
private final String twoP_twoCCommand = "twoPlayers_twoComputers";
private String btnString1 = "OK";
private String btnString2 = "Cancel";
/** Creates the reusable dialog. */
public ChoiceDialog(Frame aFrame){
super(aFrame, true);
initComponents();
}
public void initComponents(){
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
panel1 = new JPanel(new BorderLayout());
label.setHorizontalAlignment(SwingConstants.CENTER);
panel1.add(label, BorderLayout.NORTH);
panel2 = new JPanel(new GridLayout(3, 1));
// Creates a group of radio buttons
radioButtons[0] = new JRadioButton("1 Player 1 Computer");
radioButtons[0].setActionCommand(oneP_oneCCommand);
radioButtons[1] = new JRadioButton("2 Players 1 Computer");
radioButtons[1].setActionCommand(twoP_oneCCommand);
radioButtons[2] = new JRadioButton("2 Players 2 Computers");
radioButtons[2].setActionCommand(twoP_twoCCommand);
for (int i = 0; i < numButtons; i++) {
panel2.add(radioButtons[i]);
group.add(radioButtons[i]);
}
radioButtons[0].setSelected(true);
panel1.add(panel2, BorderLayout.CENTER);
panel3 = new JPanel(new FlowLayout());
buttonOK = new JButton("OK");
panel3.add(buttonOK);
buttonCancel = new JButton("Cancel");
panel3.add(buttonCancel);
panel1.add(panel3, BorderLayout.SOUTH);
getContentPane().add(panel1, java.awt.BorderLayout.CENTER);
pack();
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
new ChoiceDialog(new javax.swing.JFrame()).show();
}
} |