/
GameWindow.java
294 lines (223 loc) · 8.34 KB
/
GameWindow.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.Toolkit;
import java.net.URL;
import java.util.*;
public class GameWindow extends JPanel
{
//panels
private JPanel imgPanel;
private JPanel situationPanel;
private JPanel quitPanel;
private JPanel backnextPanel; // declares a panel
private JPanel yesnoPanel;
private JPanel skillPanel;
private JPanel sidePane;
private JPanel rightPanel;
//image
JLabel imgLabel = new JLabel(new ImageIcon("jack.jpg"));
JLabel profLabel = new JLabel(new ImageIcon("profile2.jpg"));
//situation
private JLabel situationLabel;
private JButton nextButton;
private JButton backButton;
private JButton yesButton;
private JButton noButton;
//quit button
private JButton quitButton; // QUIT BUTTON buttonLabel
//skill names
private JLabel dLabel;
private JLabel pLabel;
private JLabel cLabel;
private JLabel iLabel;
//skill values
private JLabel dskillLabel;
private JLabel pskillLabel;
private JLabel cskillLabel;
private JLabel iskillLabel;
//
// Constructor
//
public GameWindow()
{
// set this panel to a grid layout and change its color
// setBackground(Color.lightGray);
//img Panel
imgPanel = new JPanel();
imgPanel.setBackground(Color.black);
imgPanel.add(imgLabel);
//
// Situation Panel
//
situationPanel = new JPanel();
// situationPanel.setLayout(new BoxLayout(situationPanel, BoxLayout.PAGE_AXIS));
situationPanel.setBackground(Color.black);
//add(situationPanel);
situationLabel = new JLabel("");
situationLabel.setText("<html><div style=\"text-align: left;\">"+"Do you suck Sherlock's blood?"+"</html>");
situationLabel.setFont(new Font("Times New Roman", Font.PLAIN, 35));
situationLabel.setForeground(Color.WHITE);
situationPanel.add(situationLabel);
//yesnoPanel
yesnoPanel = new JPanel();
yesnoPanel.setBackground(Color.black);
// add(yesnoPanel);
yesButton = new JButton("YES"); // quits game
yesButton.addActionListener(new ButtonListener());
yesnoPanel.add(yesButton);
noButton = new JButton("NO"); // quits game
noButton.addActionListener(new ButtonListener());
yesnoPanel.add(noButton);
//backnextPanel
backnextPanel = new JPanel();
backnextPanel.setAlignmentX(Component.CENTER_ALIGNMENT);
backnextPanel.setBackground(Color.black);
// add(backnextPanel);
backButton = new JButton("Back"); // quits game
backButton.addActionListener(new ButtonListener());
backnextPanel.add(backButton);
//filler spacing between next and back button
Box.Filler hFill = new Box.Filler(new Dimension(200,0),
new Dimension(300, 0),
new Dimension(500, 0));
backnextPanel.add(hFill);
nextButton = new JButton("Next"); // quits game
nextButton.addActionListener(new ButtonListener());
backnextPanel.add(nextButton);
//skillPanel
skillPanel = new JPanel();
skillPanel.setLayout(new BoxLayout(skillPanel, BoxLayout.Y_AXIS));
skillPanel.setBackground(Color.black);
dLabel = new JLabel("Drunkenness: 5");
dLabel.setFont(new Font("Times New Roman", Font.PLAIN, 15));
dLabel.setForeground(Color.WHITE);
/*
dskillLabel = new JLabel("");
dskillLabel.setText("3");
dskillLabel.setFont(new Font("Times New Roman", Font.PLAIN, 15));
dskillLabel.setForeground(Color.RED);
*/
pLabel = new JLabel("Power: 3");
pLabel.setFont(new Font("Times New Roman", Font.PLAIN, 15));
pLabel.setForeground(Color.WHITE);
/*
pskillLabel = new JLabel("");
pskillLabel.setText("0");
pskillLabel.setFont(new Font("Times New Roman", Font.PLAIN, 15));
pskillLabel.setForeground(Color.RED);
*/
cLabel = new JLabel("Charisma: 2");
cLabel.setFont(new Font("Times New Roman", Font.PLAIN, 15));
cLabel.setForeground(Color.WHITE);
/*
cskillLabel = new JLabel("");
cskillLabel.setText("0");
cskillLabel.setFont(new Font("Times New Roman", Font.PLAIN, 15));
cskillLabel.setForeground(Color.RED);
*/
iLabel = new JLabel("Intelligence: 1");
iLabel.setFont(new Font("Times New Roman", Font.PLAIN, 15));
iLabel.setForeground(Color.WHITE);
/*
iskillLabel = new JLabel("");
iskillLabel.setText("0");
iskillLabel.setFont(new Font("Times New Roman", Font.PLAIN, 15));
iskillLabel.setForeground(Color.RED);
*/
//adding image and labels to skillPanel
skillPanel.add(profLabel);
skillPanel.add(dLabel);
//skillPanel.add(dskillLabel);
Box.Filler dFill = new Box.Filler(new Dimension(5,15),
new Dimension(5,15),
new Dimension(5, 15));
skillPanel.add(dFill);
skillPanel.add(pLabel);
//skillPanel.add(pskillLabel);
//skillPanel.add((Box.createVerticalGlue()));
Box.Filler pFill = new Box.Filler(new Dimension(5,15),
new Dimension(5,15),
new Dimension(5, 15));
skillPanel.add(pFill);
skillPanel.add(cLabel);
//skillPanel.add(cskillLabel);
Box.Filler cFill = new Box.Filler(new Dimension(5,15),
new Dimension(5,15),
new Dimension(5, 15));
skillPanel.add(cFill);
skillPanel.add(iLabel);
//skillPanel.add(iskillLabel);
/*
JPanel skillvalPanel = new JPanel();
skillvalPanel.setLayout(new BoxLayout(skillvalPanel, BoxLayout.Y_AXIS));
skillvalPanel.setBackground(Color.black);
dskillLabel = new JLabel("");
dskillLabel.setText("3");
dskillLabel.setFont(new Font("Times New Roman", Font.PLAIN, 15));
dskillLabel.setForeground(Color.RED);
skillvalPanel.add(dskillLabel);
*/
//
// quitPanel
//
quitPanel = new JPanel();
quitPanel.setBackground(Color.black);
quitButton = new JButton("QUIT"); // quits game
quitButton.addActionListener(new ButtonListener());
quitPanel.add(quitButton);
rightPanel = new JPanel();
rightPanel.setLayout(new BoxLayout(rightPanel, BoxLayout.Y_AXIS));
rightPanel.setBackground(Color.BLACK);
rightPanel.add(imgPanel);
rightPanel.add(situationPanel);
rightPanel.add(backnextPanel);
rightPanel.add(yesnoPanel);
rightPanel.add(quitPanel);
//add skillPanel to sidePane
sidePane = new JPanel(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
c.fill = GridBagConstraints.HORIZONTAL;
sidePane.setBackground(Color.BLACK);
//c.ipadx = 100;
// c.ipady= 300;
sidePane.add(skillPanel,c);
//sidePane.add(skillvalPanel,c);
add(sidePane);
JPanel right= new JPanel(new GridBagLayout());
right.setBackground(Color.BLACK);
GridBagConstraints r = new GridBagConstraints();
// r.fill = GridBagConstraints.VERTICAL;
// r.ipadx =900;
//r.ipady =500;
right.add(rightPanel);
add(right);
this.setBackground(Color.BLACK);
}
/**
* ButtonListener is a private class for responding to button push events
*/
private class ButtonListener implements ActionListener {
/** quits the game if quit button is pushed, changes the text of the buttons
**/
public void actionPerformed (ActionEvent event)
{
//quit button was pressed
if (event.getSource() == quitButton) System.exit(0);
}
}
public static void main(String[] args){
JFrame frame = new JFrame ("Wah, wah, waaaahh....");
// creates a new frame
frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE); // makes a functional exit operation
JPanel pane = new JPanel(new GridBagLayout());
pane.setBackground(Color.BLACK);
// adding the tabs which have panels to the tabbed panel
pane.add (new GameWindow());
frame.getContentPane().add(pane); // adding the pane to the frame
frame.pack(); // unpacking what we need
//frame.setSize(950,650); //sets the size after unpacking
frame.setResizable(false); //frame can no longer can be resized
frame.setVisible(true); // make the frame/everything? visible
}
}