-
Notifications
You must be signed in to change notification settings - Fork 0
/
WarnBackFrame.java
100 lines (79 loc) · 2.57 KB
/
WarnBackFrame.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
// Aaryan Prakash
// 5/10/18
// WarnBackFrame.java
// This opens up when the user clicks out of the GamePanel panel so that
// the user knows this will reset the game.
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JButton;
import javax.swing.JTextArea;
import javax.swing.JRootPane;
import java.awt.BorderLayout;
import java.awt.CardLayout;
import java.awt.Font;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
public class WarnBackFrame
{
// names of buttons to exit game or close warning
private final String EXIT_NAME = new String("Close Game");
private final String CANCEL_NAME = new String("Back to Game");
private Font sansSerif28; // font that is SansSerif, plain, and size 28
private GameHolder holder; // variable for panel that holds cards
private CardLayout cards; // variable for CardLayout
private JFrame frame; // frame that pops up
// passes in holder
public WarnBackFrame(GameHolder holderIn, CardLayout cardsIn)
{
sansSerif28 = new Font("Arial", Font.PLAIN, 28);
holder = holderIn;
cards = cardsIn;
}
// creates frame and shows to user
public void createFrame()
{
frame = new JFrame();
frame.setSize(600, 348);
frame.setDefaultCloseOperation(frame.HIDE_ON_CLOSE);
frame.setResizable(false);
frame.setLocation(300, 426);
JPanel holds = new JPanel();
holds.setLayout(new BorderLayout());
// removes top
frame.setUndecorated(true);
frame.getRootPane().setWindowDecorationStyle(JRootPane.NONE);
JTextArea warning = new JTextArea("", 10, 10);
warning.setText(" Warning!\n"
+ "If you close the game, the game will reset! Are you sure"
+ " that you want to continue?");
warning.setFont(sansSerif28);
warning.setWrapStyleWord(true);
warning.setLineWrap(true);
warning.setEditable(false);
holds.add(warning, BorderLayout.NORTH);
JPanel bottom = new JPanel();
JButton exit = new JButton(EXIT_NAME);
JButton cancel = new JButton(CANCEL_NAME);
exit.addActionListener(new ButtonListener());
cancel.addActionListener(new ButtonListener());
bottom.add(exit);
bottom.add(cancel);
holds.add(bottom, BorderLayout.CENTER);
frame.getContentPane().add(holds);
frame.setVisible(true);
}
// listener for buttons
class ButtonListener implements ActionListener
{
public void actionPerformed(ActionEvent evt)
{
String source = evt.getActionCommand();
// goes back to normal start screen
if (source.equals(EXIT_NAME))
{
cards.show(holder, holder.getStartName());
}
frame.setVisible(false);
}
}
}