-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSettingOptions.java
68 lines (46 loc) · 1.9 KB
/
SettingOptions.java
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
import java.awt.* ;
import java.awt.event.* ;
import javax.swing.* ;
public class SettingOptions extends JFrame {
private GameController gameController ;
public SettingOptions(GameController gameController){
this.gameController = gameController ;
JRadioButton plane = new JRadioButton("Plane");
plane.setActionCommand("Plane");
JRadioButton torus = new JRadioButton("Torus");
torus.setActionCommand("Torus");
JRadioButton orthogonal = new JRadioButton("Orthogonal");
orthogonal.setActionCommand("Orthogonal");
JRadioButton diagonals = new JRadioButton("Diagonals");
diagonals.setActionCommand("Diagonals");
JButton ok = new JButton ("OK");
ok.addActionListener(gameController) ;
// add event handler
plane.addActionListener(gameController) ;
torus.addActionListener(gameController) ;
orthogonal.addActionListener(gameController) ;
diagonals.addActionListener(gameController) ;
// add radio buttons to a ButtonGroup
final ButtonGroup group1 = new ButtonGroup();
group1.add(plane);
group1.add(torus);
plane.setSelected(true) ;
final ButtonGroup group2 = new ButtonGroup();
group2.add(orthogonal);
group2.add(diagonals);
orthogonal.setSelected(true) ;
// Frame setting
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
setSize(300, 200);
Container cont = getContentPane();
cont.setLayout(new GridLayout(0, 1));
cont.add(new JLabel("Play on plane or torus?"));
cont.add(plane);
cont.add(torus);
cont.add(new JLabel("Diagonal moves"));
cont.add(orthogonal);
cont.add(diagonals);
add(ok,BorderLayout.SOUTH);
setVisible(true);
}
}