-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGameOverWindow.java
More file actions
94 lines (80 loc) · 2.81 KB
/
GameOverWindow.java
File metadata and controls
94 lines (80 loc) · 2.81 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
81
82
83
84
85
86
87
88
89
90
91
92
93
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import javax.swing.border.*;
/** Window that pops up when the user either "wins" or "loses" game.
*
* @author Gemma Smith <gemma.smith@tufts.edu>
* @version 1.0
* @since 2013-11-29
*/
public class GameOverWindow extends JFrame
{
private JLabel gameOverTitle;
private Main main;
public GameOverWindow(Main mn)
{
super("Game Over");
setSize(410,125);
main = mn;
JPanel gameOverPanel = new JPanel();
gameOverPanel.setLayout(new BoxLayout(gameOverPanel, BoxLayout.Y_AXIS));
gameOverPanel.setOpaque(true);
gameOverPanel.setBackground(Color.WHITE);
gameOverTitle = new JLabel ("Game over.", JLabel.CENTER);
gameOverTitle.setFont(new Font("SansSerif", Font.BOLD, 18));
gameOverTitle.setForeground(Color.RED);
gameOverTitle.setAlignmentX(Component.CENTER_ALIGNMENT);
gameOverPanel.add(gameOverTitle);
JLabel subTitle = new JLabel("Would you like to play again?",
JLabel.CENTER);
subTitle.setFont(new Font("SansSerif", Font.PLAIN, 14));
subTitle.setAlignmentX(Component.CENTER_ALIGNMENT);
gameOverPanel.add(subTitle);
MyButton playAgain = new MyButton("Start over", Color.BLACK, 12);
playAgain.addActionListener(new startOverListener(true, this));
playAgain.setAlignmentX(Component.CENTER_ALIGNMENT);
gameOverPanel.add(playAgain);
MyButton quit = new MyButton("Quit", Color.BLACK, 12);
quit.addActionListener(new startOverListener(false, this));
quit.setAlignmentX(Component.CENTER_ALIGNMENT);
gameOverPanel.add(quit);
add(gameOverPanel);
setLocation(100,100);
}
/** Sets the text in the window to newTitle.
* @param newTitle text to display
*/
public void setTitle(String newTitle)
{
gameOverTitle.setText(newTitle);
}
/** Class to implement ActionListener for the playAgain and quit buttons.
*/
class startOverListener implements ActionListener
{
private boolean startOver;
private GameOverWindow window;
public startOverListener(boolean bool, GameOverWindow w)
{
window = w;
startOver = bool;
}
/** Upon clicking either the playAgain or quit buttons, the
* GameOverWindow closes and the game either starts over or quits.
*/
public void actionPerformed(ActionEvent event)
{
if (startOver)
{
window.setVisible(false);
main.openSaveScoreWindow();
}
else
{
window.setVisible(false);
main.quit();
}
}
}
}