Tree2
[siwg.git] / Connect6 / src / GUI.java
blob6d045466e7d5e774aaf04ba59e896544069cc2a0
1 import java.awt.BorderLayout;
2 import java.awt.Container;
3 import java.awt.Dimension;
4 import java.awt.event.ActionEvent;
5 import java.awt.event.ActionListener;
7 import javax.swing.JFrame;
8 import javax.swing.JMenu;
9 import javax.swing.JMenuBar;
10 import javax.swing.JMenuItem;
11 import javax.swing.JOptionPane;
12 import javax.swing.JPopupMenu;
15 public class GUI extends JFrame {
17 private static final long serialVersionUID = 6411499808530678723L;
18 private JMenuBar menuBar;
19 private Mechanics mechanics;
21 public GUI(String name) {
22 super(name);
23 setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
24 setSize(new Dimension(800,600));
25 createMenuBar();
26 setJMenuBar(menuBar);
27 JPopupMenu.setDefaultLightWeightPopupEnabled( false );
30 private void createMenuBar() {
31 menuBar = new JMenuBar();
32 JMenu menu1 = new JMenu("Game");
33 JMenu menu2 = new JMenu("Mode");
34 JMenu menu3 = new JMenu("Action");
35 JMenu menu4 = new JMenu("Options");
36 JMenu menu5 = new JMenu("Help");
37 menuBar.add(menu1);
38 menuBar.add(menu2);
39 menuBar.add(menu3);
40 menuBar.add(menu4);
41 menuBar.add(menu5);
43 JMenuItem item1 = new JMenuItem("Create Server");
44 JMenuItem item2 = new JMenuItem("Join server");
45 JMenuItem item3 = new JMenuItem("Disconnect");
46 JMenuItem item4 = new JMenuItem("Close");
47 item4.addActionListener(new ActionListener() {
48 @Override
49 public void actionPerformed(ActionEvent arg0) {
50 System.exit(0);
52 });
53 menu1.add(item1);
54 menu1.add(item2);
55 menu1.add(item3);
56 menu1.add(item4);
58 JMenuItem item5 = new JMenuItem("Player vs player");
59 item5.addActionListener(new ActionListener() {
60 @Override
61 public void actionPerformed(ActionEvent arg0) {
62 Container game = new Container();
63 Board board = new Board();
64 ChessClockGui ccg = new ChessClockGui("Player1", "Player2", true);
65 mechanics = new GameMechanics(ccg, board, true, true, null, null, 600000);
66 //menuBar = new JMenuBar();
68 game.setLayout(new BorderLayout());
69 game.add(ccg, BorderLayout.NORTH);
70 game.add(board, BorderLayout.CENTER);
71 game.setSize(board.getSize());
72 GUI.this.setContentPane(game);
73 GUI.this.setSize(board.getSize());
74 GUI.this.validate();
76 });
77 JMenuItem item6 = new JMenu("Player vs cpu");
78 JMenuItem item6_1 = new JMenuItem("Play as White");
79 item6_1.addActionListener(new ActionListener() {
80 @Override
81 public void actionPerformed(ActionEvent arg0) {
82 Container game = new Container();
83 Board board = new Board();
84 ChessClockGui ccg = new ChessClockGui("Player1", "CPU2", true);
85 String s = (String)JOptionPane.showInputDialog(
86 board,
87 "Program path:",
88 "Customized Dialog",
89 JOptionPane.PLAIN_MESSAGE,
90 null,
91 null, "");
92 if (s == null || s.equals("")) {
93 return;
95 mechanics = new GameMechanics(ccg, board, true, false, null, s, 600000);
96 //menuBar = new JMenuBar();
98 game.setLayout(new BorderLayout());
99 game.add(ccg, BorderLayout.NORTH);
100 game.add(board, BorderLayout.CENTER);
101 game.setSize(board.getSize());
102 GUI.this.setContentPane(game);
103 GUI.this.setSize(board.getSize());
104 GUI.this.validate();
107 JMenuItem item6_2 = new JMenuItem("Play as Black");
108 item6_2.addActionListener(new ActionListener() {
109 @Override
110 public void actionPerformed(ActionEvent arg0) {
111 Container game = new Container();
112 Board board = new Board();
113 ChessClockGui ccg = new ChessClockGui("CPU1", "Player2", true);
114 String s = (String)JOptionPane.showInputDialog(
115 board,
116 "Program path:",
117 "Customized Dialog",
118 JOptionPane.PLAIN_MESSAGE,
119 null,
120 null, "");
121 if (s == null || s.equals("")) {
122 return;
124 mechanics = new GameMechanics(ccg, board, false, true, s, null, 600000);
125 //menuBar = new JMenuBar();
127 game.setLayout(new BorderLayout());
128 game.add(ccg, BorderLayout.NORTH);
129 game.add(board, BorderLayout.CENTER);
130 game.setSize(board.getSize());
131 GUI.this.setContentPane(game);
132 GUI.this.setSize(board.getSize());
133 GUI.this.validate();
136 JMenuItem item7 = new JMenuItem("Cpu vs cpu");
137 item7.addActionListener(new ActionListener() {
138 @Override
139 public void actionPerformed(ActionEvent arg0) {
140 Container game = new Container();
141 Board board = new Board();
142 ChessClockGui ccg = new ChessClockGui("CPU1", "CPU2", true);
143 String s1 = (String)JOptionPane.showInputDialog(
144 board,
145 "Program path:",
146 "Customized Dialog",
147 JOptionPane.PLAIN_MESSAGE,
148 null,
149 null, "");
150 if (s1 == null || s1.equals("")) {
151 return;
153 String s2 = (String)JOptionPane.showInputDialog(
154 board,
155 "Program path:",
156 "Customized Dialog",
157 JOptionPane.PLAIN_MESSAGE,
158 null,
159 null, "");
160 if (s2 == null || s2.equals("")) {
161 return;
163 mechanics = new GameMechanics(ccg, board, false, false, s1, s2, 600000);
164 //menuBar = new JMenuBar();
166 game.setLayout(new BorderLayout());
167 game.add(ccg, BorderLayout.NORTH);
168 game.add(board, BorderLayout.CENTER);
169 game.setSize(board.getSize());
170 GUI.this.setContentPane(game);
171 GUI.this.setSize(board.getSize());
172 GUI.this.validate();
175 //JMenuItem item8 = new JMenuItem("Editing board");
176 JMenuItem item14 = new JMenuItem("Analyze");
177 item14.addActionListener(new ActionListener() {
179 @Override
180 public void actionPerformed(ActionEvent arg0) {
181 Container analyst = new Container();
182 Board board = new Board();
183 AnalystWindow aw = new AnalystWindow();
184 mechanics = new AnalystMechanics(board, aw);
186 analyst.setLayout(new BorderLayout());
187 analyst.add(aw, BorderLayout.NORTH);
188 analyst.add(board, BorderLayout.CENTER);
189 analyst.setSize(board.getSize());
190 GUI.this.setContentPane(analyst);
191 GUI.this.setSize(board.getSize());
192 aw.setSize(board.getSize().width, 100);
193 aw.setMaximumSize(aw.getSize());
194 GUI.this.validate();
195 //GUI.this.setComponentZOrder(menuBar, -2);
198 menu2.add(item5);
199 menu2.add(item6);
200 menu2.add(item7);
201 //menu2.add(item8);
202 menu2.add(item14);
204 item6.add(item6_1);
205 item6.add(item6_2);
207 JMenuItem item9 = new JMenuItem("Surrender");
208 item9.addActionListener(new ActionListener() {
210 @Override
211 public void actionPerformed(ActionEvent arg0) {
212 if (mechanics != null) {
213 mechanics.surrenderCalled();
217 JMenuItem item13 = new JMenuItem("Force move");
218 item13.addActionListener(new ActionListener() {
220 @Override
221 public void actionPerformed(ActionEvent e) {
222 if (mechanics != null) {
223 mechanics.forceMove();
227 menu3.add(item9);
228 menu3.add(item13);
230 JMenuItem item10 = new JMenuItem("Whatever1");
231 JMenuItem item11 = new JMenuItem("Whatever2");
232 menu4.add(item10);
233 menu4.add(item11);
235 JMenuItem item12 = new JMenuItem("About");
236 item12.addActionListener(new ActionListener() {
238 @Override
239 public void actionPerformed(ActionEvent arg0) {
240 JOptionPane.showMessageDialog(GUI.this, "It's ugly GUI v0.2!");
243 menu5.add(item12);