-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathResultWindow.java
More file actions
80 lines (68 loc) · 2.14 KB
/
Copy pathResultWindow.java
File metadata and controls
80 lines (68 loc) · 2.14 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import java.awt.Color;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class ResultWindow extends JFrame {
String imagePath;
JPanel resultPane;
Board instance;
public ResultWindow(int type, Board instance) {
// Type 0 = loss, 1 = win
if (type == 0) {
imagePath = "Win.png";
} else if (type == 1) {
imagePath = "Lose.png";
}
this.instance = instance;
this.setTitle("Result");
this.setSize(850, 400);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setLocationRelativeTo(null);
this.setVisible(true);
this.setResizable(false);
this.setContentPane(createWindow());
}
private JPanel createWindow() {
resultPane = new JPanel();
ImageIcon image = new ImageIcon(imagePath);
JLabel iconLbl = new JLabel();
iconLbl.setIcon(image);
resultPane.add(iconLbl);
JButton newGame = new JButton("New Game");
newGame.addActionListener(new NewButtonListener());
newGame.setFont(new Font("Verdana", Font.PLAIN, 20));
resultPane.add(newGame);
JButton restart = new JButton("Restart");
restart.addActionListener(new RestartButtonListener());
restart.setFont(new Font("Verdana", Font.PLAIN, 20));
resultPane.add(restart);
JButton review = new JButton("Review");
review.addActionListener(new ReviewButtonListener());
review.setFont(new Font("Verdana", Font.PLAIN, 20));
resultPane.add(review);
resultPane.setBackground(new Color(206, 202, 212));
return resultPane;
}
class NewButtonListener implements ActionListener {
public void actionPerformed(ActionEvent event) {
instance.restartGame(0);
dispose();
}
}
class RestartButtonListener implements ActionListener {
public void actionPerformed(ActionEvent event) {
instance.restartGame(3);
dispose();
}
}
class ReviewButtonListener implements ActionListener {
public void actionPerformed(ActionEvent event) {
dispose();
}
}
}