-
Notifications
You must be signed in to change notification settings - Fork 0
/
DialogClass.java
106 lines (88 loc) · 2.97 KB
/
DialogClass.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
// Author: Matthew Leung
// ICS4U1 Final Project
// Penguin Solitaire
import java.awt.*;
import java.awt.event.*;
public class DialogClass //used to create dialog boxes
{
private static Dialog d;
DialogClass ()
{
}
DialogClass (int type)
{
if ((type == 1) || (type == 2))
{
Frame f = new Frame ();
Button by, bn;
Label confirm;
if (type == 1) //dialog box that confirms if the player wants to restart
{
d = new Dialog (f, "Warning", true);
by = new Button ("Yes");
bn = new Button ("No");
confirm = new Label ("Are you sure you want to restart?");
}
else //dialog box that asks player if they want to play again
{
d = new Dialog (f, "Game Won", true);
by = new Button ("Play Again");
bn = new Button ("Exit");
confirm = new Label ("Congratulations! You won the game!");
}
d.setLocationRelativeTo (null);
d.setSize (300, 125);
////////////////////////////////////////////////////////////////////
by.addActionListener (new ActionListener () //takes care of what happens when each button is pressed
{
public void actionPerformed (ActionEvent e)
{
DialogClass.d.setVisible (false); //close the dialog
Main.dialogCommunicator = true; //used to pass information over to Main
}
}
);
bn.addActionListener (new ActionListener ()
{
public void actionPerformed (ActionEvent e)
{
DialogClass.d.setVisible (false); //close the dialog
Main.dialogCommunicator = false; //used to pass information over to Main
}
}
);
////////////////////////////////////////////////////////////////////
BorderLayout lm = new BorderLayout (); //layout manager for d
d.setLayout (lm);
////////////////////////////////////////////////////////////////////
Panel pdeNorth = new Panel (); //add a FlowLayout to the "North" panel
pdeNorth.setLayout (new FlowLayout ());
pdeNorth.add (confirm);
d.add ("North", pdeNorth);
////////////////////////////////////////////////////////////////////
Panel pdeSouth = new Panel (); //add a GridBagLayout to the "South" panel
GridBagLayout lmgb = new GridBagLayout ();
pdeSouth.setLayout (lmgb);
GridBagConstraints gbc = new GridBagConstraints ();
gbc.weightx = 1;
gbc.weighty = 1;
gbc.gridx = 2;
gbc.gridy = 0;
lmgb.setConstraints (by, gbc);
pdeSouth.add (by, gbc);
gbc.gridx = 3;
gbc.gridy = 0;
lmgb.setConstraints (bn, gbc);
pdeSouth.add (bn, gbc);
gbc.gridx = 0; //included to improve spacing
gbc.gridy = 1;
pdeSouth.add (new Label (""), gbc);
gbc.gridx = 4; //included to improve spacing
gbc.gridy = 1;
pdeSouth.add (new Label (""), gbc);
d.add ("South", pdeSouth);
////////////////////////////////////////////////////////////////////
d.setVisible (true);
}
}
}