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
) {
23 setDefaultCloseOperation(JFrame
.EXIT_ON_CLOSE
);
24 setSize(new Dimension(800,600));
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");
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() {
49 public void actionPerformed(ActionEvent arg0
) {
58 JMenuItem item5
= new JMenuItem("Player vs player");
59 item5
.addActionListener(new ActionListener() {
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());
77 JMenuItem item6
= new JMenu("Player vs cpu");
78 JMenuItem item6_1
= new JMenuItem("Play as White");
79 item6_1
.addActionListener(new ActionListener() {
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(
89 JOptionPane
.PLAIN_MESSAGE
,
92 if (s
== null || s
.equals("")) {
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());
107 JMenuItem item6_2
= new JMenuItem("Play as Black");
108 item6_2
.addActionListener(new ActionListener() {
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(
118 JOptionPane
.PLAIN_MESSAGE
,
121 if (s
== null || s
.equals("")) {
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());
136 JMenuItem item7
= new JMenuItem("Cpu vs cpu");
137 item7
.addActionListener(new ActionListener() {
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(
147 JOptionPane
.PLAIN_MESSAGE
,
150 if (s1
== null || s1
.equals("")) {
153 String s2
= (String
)JOptionPane
.showInputDialog(
157 JOptionPane
.PLAIN_MESSAGE
,
160 if (s2
== null || s2
.equals("")) {
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());
175 //JMenuItem item8 = new JMenuItem("Editing board");
176 JMenuItem item14
= new JMenuItem("Analyze");
177 item14
.addActionListener(new ActionListener() {
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());
195 //GUI.this.setComponentZOrder(menuBar, -2);
207 JMenuItem item9
= new JMenuItem("Surrender");
208 item9
.addActionListener(new ActionListener() {
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() {
221 public void actionPerformed(ActionEvent e
) {
222 if (mechanics
!= null) {
223 mechanics
.forceMove();
230 JMenuItem item10
= new JMenuItem("Whatever1");
231 JMenuItem item11
= new JMenuItem("Whatever2");
235 JMenuItem item12
= new JMenuItem("About");
236 item12
.addActionListener(new ActionListener() {
239 public void actionPerformed(ActionEvent arg0
) {
240 JOptionPane
.showMessageDialog(GUI
.this, "It's ugly GUI v0.2!");