-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGame.java
More file actions
62 lines (47 loc) · 1.51 KB
/
Game.java
File metadata and controls
62 lines (47 loc) · 1.51 KB
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
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
@SuppressWarnings("serial")
public class Game extends JFrame implements Runnable{
private static int WIDTH = 650;
private static int HEIGHT = 650;
public void run() {
final JFrame frame = new JFrame("Chess");
frame.setSize(WIDTH,HEIGHT);
final JToolBar toolBar = new JToolBar();
frame.add(toolBar, BorderLayout.NORTH);
final ChessBoard chessboard = new ChessBoard();
frame.getContentPane().add(chessboard, BorderLayout.CENTER);
final JButton reset = new JButton("New");
reset.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
chessboard.reset();
ChessBoard newCB = (ChessBoard) frame.getContentPane().getComponent(1);
newCB.reset();
frame.getContentPane().remove(newCB);
frame.getContentPane().add(new ChessBoard());
}
});
toolBar.add(reset);
final JButton quit = new JButton("Quit");
quit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
frame.dispose();
}
});
toolBar.add(quit);
final JButton resign = new JButton("Resign");
resign.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
chessboard.resign();
}
});
toolBar.add(resign);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Game());
}
}