-
Notifications
You must be signed in to change notification settings - Fork 1
/
MyMenu.java
83 lines (70 loc) · 2.34 KB
/
MyMenu.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class MyMenu extends JFrame {
private JButton single, multi, setting, exit;
private JPanel globalPanel, setPanel;
private MainFrame mainFrame;
public int turn;
public int level;
MyMenu(String s) {
super(s);
globalPanel = new JPanel();
setPanel = new JPanel();
setPanel.setLayout(new FlowLayout());
MenuActionListener listener = new MenuActionListener();
single = new JButton("Single Player");
single.addActionListener(listener);
multi = new JButton("Multi Player");
multi.addActionListener(listener);
setting = new JButton("setting");
setting.addActionListener(listener);
exit = new JButton("exit");
exit.addActionListener(listener);
setPanel.add(setting);
setPanel.add(exit);
globalPanel.setLayout(new GridLayout(5, 1));
JPanel sP, mP, eP;
sP = new JPanel();
sP.add(single);
mP = new JPanel();
mP.add(multi);
eP = new JPanel();
globalPanel.add(eP);
globalPanel.add(sP);
// globalPanel.add(eP);
globalPanel.add(mP);
globalPanel.add(setPanel);
turn = 1;
level = 3;
setContentPane(globalPanel);
setSize(300, 200);
setLocation(500, 250);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
}
public static void main(String args[]) {
MyMenu m = new MyMenu("Othello");
}
class MenuActionListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
JButton source = (JButton)e.getSource();
if(source == single || source == multi) {
MyMenu.this.setVisible(false);
mainFrame = new MainFrame();
mainFrame.setAi(source == single);
mainFrame.setTurn(turn);
mainFrame.setLevel(level);
mainFrame.myMenu = MyMenu.this;
} else {
if(source == exit) {
MyMenu.this.dispose();
} else {
SetTurn s = new SetTurn();
s.myMenu = MyMenu.this;
MyMenu.this.setVisible(false);
}
}
}
}
}