-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGameWinDia.java
112 lines (88 loc) · 2.53 KB
/
GameWinDia.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package frame;
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.GridLayout;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import util.SaveFile;
@SuppressWarnings("serial")
public class GameWinDia extends JDialog implements ActionListener, WindowListener{
private GamePanel gPanel;
public GameWinDia(GamePanel gPanel) {
this.gPanel = gPanel;
setTitle("Win the Game");
setLocationRelativeTo(gPanel);
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
addWindowListener(this);
initComponents();
setModal(true);
setResizable(false);
pack();
setVisible(true);
}
public void initComponents() {
// first - note
JLabel noteLabel = new JLabel("Congratulation! You win the Game.");
JPanel notePanel = new JPanel();
notePanel.setLayout(new BorderLayout());
notePanel.add(noteLabel, BorderLayout.CENTER);
notePanel.setBorder(BorderFactory.createEmptyBorder(20, 50, 20, 50));
// second - two buttons
JButton exitButton = new JButton("Exit");
JButton replayButton = new JButton("Play another game");
exitButton.addActionListener(this);
replayButton.addActionListener(this);
JPanel buttonPanel = new JPanel();
buttonPanel.setLayout(new GridLayout(1, 2));
buttonPanel.add(exitButton);
buttonPanel.add(replayButton);
buttonPanel.setBorder(BorderFactory.createEmptyBorder(40, 5, 20, 5));
// add panels to the game
Container c = getContentPane();
c.setLayout(new GridLayout(2, 1));
c.add(notePanel);
c.add(buttonPanel);
}
@Override
public void actionPerformed(ActionEvent e) {
if(e.getSource().toString().indexOf("Exit") != -1) {
SaveFile.output();
System.exit(0);
} else if(e.getSource().toString().indexOf("Play another game") != -1) {
gPanel.playAnotherGame();
dispose();
}
}
@Override
public void windowActivated(WindowEvent e) {
}
@Override
public void windowClosed(WindowEvent e) {
}
@Override
public void windowClosing(WindowEvent e) {
gPanel.playAnotherGame();
}
@Override
public void windowDeactivated(WindowEvent e) {
}
@Override
public void windowDeiconified(WindowEvent e) {
}
@Override
public void windowIconified(WindowEvent e) {
}
@Override
public void windowOpened(WindowEvent e) {
}
}