-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain_view.java
More file actions
196 lines (159 loc) · 5.61 KB
/
main_view.java
File metadata and controls
196 lines (159 loc) · 5.61 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
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
import java.applet.Applet;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.net.MalformedURLException;
import java.net.URL;
import javax.swing.Box;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JProgressBar;
public class main_view extends JPanel implements ActionListener {
JButton pauseButton;
static gameManager theMgr;
public JLabel boardNum = new JLabel("");
public JProgressBar timeBar;
public JLabel timeLabel ;
public JPanel nums;
public Dimension pauseButtonDim;
JLabel gameDisplay;
Box scoreBox;
URL snd1;
URL snd;
URL snd3;
public JLabel score = new JLabel("0");
public JLabel level = new JLabel("0");
Box level_life_box;
main_view() {
theMgr = new gameManager(120,2,this);
this.setLayout(new BorderLayout());
setSize(500,500);
gameDisplay = new JLabel("");
setPreferredSize(new Dimension(500,500));
setMaximumSize(getPreferredSize());
setMinimumSize(getPreferredSize());
// Bottom stuff
Box b4_bottom =Box.createHorizontalBox();
b4_bottom.setSize(498,60);
Box bottom = Box.createHorizontalBox();
bottom.setSize(498,40);
boardNum.setFont(new Font(Font.SERIF, Font.BOLD, 30));
boardNum.setForeground(Color.WHITE);
this.setBackground(new Color(35,35,35));
timeLabel = new JLabel("0");
timeLabel.setSize(35,90);
timeLabel.setForeground(Color.YELLOW);
timeBar = new JProgressBar(0,15);
timeBar.setBorder(null);
timeBar.setBorderPainted(false);
timeBar.setForeground(new Color(14*14,14+7,4));
pauseButton = new JButton(" Pause ");
pauseButton.setBackground(new Color(82,82,82));
pauseButton.setBorder(null);
pauseButton.setForeground((Color.white));
pauseButtonDim = pauseButton.getSize();
scoreBox = Box.createVerticalBox();
scoreBox.setSize(200,150);
scoreBox.add(new JLabel("Score"));
scoreBox.add(score);
score.setForeground(Color.white);
level_life_box = Box.createVerticalBox();
level_life_box.add(new JLabel("Level"));
level_life_box.add(level);
level.setForeground(Color.white);
scoreBox.setSize(200,150);
bottom.add(Box.createHorizontalStrut(10));
bottom.add(timeLabel);
bottom.add(Box.createHorizontalStrut(20));
bottom.add(timeBar);
bottom.add(Box.createHorizontalStrut(20));
bottom.add(pauseButton);
bottom.add(Box.createHorizontalStrut(10));
b4_bottom.add(Box.createHorizontalStrut(10));
b4_bottom.add(scoreBox);
b4_bottom.add(Box.createHorizontalStrut(165));
Box boardNumBox = Box.createVerticalBox();
boardNumBox.add(boardNum);
boardNumBox.setSize(100,50);
b4_bottom.add(Box.createHorizontalGlue());
b4_bottom.add(boardNumBox);
b4_bottom.add(Box.createHorizontalStrut(145));
b4_bottom.add(level_life_box);
b4_bottom.add(Box.createHorizontalGlue());
Box vertBox = Box.createVerticalBox();
vertBox.add(b4_bottom);
vertBox.add(bottom);
vertBox.add(Box.createVerticalStrut(8));
this.add(vertBox, BorderLayout.SOUTH);
// end of bottom stuff
// numbers panel
nums = new JPanel();
for(int i = 0; i<theMgr.numArray.length; i++){
nums.add(getNum(theMgr.numArray[i]));
}
boardNum.setText(""+theMgr.getAskingValue());
nums.setSize(350,350);
nums.setBackground(new Color(2,5,6));
this.add(nums,BorderLayout.CENTER);
setVisible(true);
pauseButton.addActionListener(this);
timeLabel.requestFocus();
}
public main_view startGame(){
return new main_view();
}
public JButton getNum(int num){
JButton it = new JButton(""+num);
it.setSize(105,50);
it.setBackground(new Color(num*12,num*14,num*2));
it.setForeground(Color.WHITE);
it.addActionListener(this);
return it;
}
public void actionPerformed(ActionEvent e){
JButton theButtonPressed = ((JButton)(e.getSource()));
if(theButtonPressed.getBackground()== Color.red){
return;
}
if(!(theButtonPressed.getBackground()== Color.red || theButtonPressed.getBackground()== Color.BLACK) && e.getActionCommand().equalsIgnoreCase("1") ||
e.getActionCommand().equalsIgnoreCase("2") ||
e.getActionCommand().equalsIgnoreCase("3") ||
e.getActionCommand().equalsIgnoreCase("4") ||
e.getActionCommand().equalsIgnoreCase("5") ||
e.getActionCommand().equalsIgnoreCase("6") ||
e.getActionCommand().equalsIgnoreCase("7") ||
e.getActionCommand().equalsIgnoreCase("8") ||
e.getActionCommand().equalsIgnoreCase("9") ){
theButtonPressed.setBackground(Color.red);
theMgr.stackSum(Integer.parseInt(theButtonPressed.getText()), theButtonPressed,this);
boardNum.setText(""+theMgr.currentAskingValue);
timeLabel.requestFocus(); // dont want the button focused after a press.
}
if(e.getActionCommand().equalsIgnoreCase(" Pause ")){
JButton it = ((JButton)e.getSource());
it.setText("Continue");
it.setBackground(new Color(82,82,82));
nums.setVisible(false);
this.add(gameDisplay);
gameDisplay.setText(" GAME PAUSED");
gameDisplay.setFont(new Font(Font.SERIF,Font.PLAIN, 62));
this.validate();
theMgr.pauseGame();
timeLabel.requestFocus();
}
if(e.getActionCommand().equalsIgnoreCase("Continue")){
JButton it = ((JButton)e.getSource());
it.setText(" Pause ");
it.setBackground(new Color(82,82,82));
this.remove(gameDisplay);
nums.setVisible(true);
this.validate();
theMgr.resumeGame();
timeLabel.requestFocus();
}
}
}