-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJCLevels.java
More file actions
242 lines (214 loc) · 7.08 KB
/
JCLevels.java
File metadata and controls
242 lines (214 loc) · 7.08 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
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
//Christina Lau and Jasmine Wang
//4-20-15
//JC1.java is the menu of the game, it leads to the game, instructions, and credits
import java.awt.*; //import libraries
import javax.swing.*;
import java.awt.event.*;
import javax.swing.event.*;
public class JCLevels extends JPanel//jframe
{
Panel1 panel1= new Panel1();
Panel2 panel2= new Panel2();
Panel3 panel3= new Panel3();
Panel4 panel4= new Panel4();
CardPages cP;
CardLayout ccc;
JCLevels()
{
setLayout(new GridLayout(1, 1, 0, 0));
cP = new CardPages(); // object for pages CardLayout class
add(cP); // add CardLayout object to the container
ccc.show(cP, "p1");
}
class CardPages extends JPanel//class five implements ActionListener, is a cardlayout
{
public CardPages()
{
ccc = new CardLayout(); // create CardLayout object
setLayout(ccc); // set to CardLayout
add(panel1, "p1"); // add classes objects as card pages
add(panel2, "p2");
add(panel3, "p3");
add(panel4, "p4");
}
}
class Panel1 extends JPanel implements MouseListener, MouseMotionListener{//class Panel 1 is the Menu page, it has three buttons on it "Start Game", "Instructions", and "Credits", buttons will change cards
private Image levelspic;
private boolean integers = false;
private boolean addition = false;
private boolean subtraction = false;
public Panel1()
{
addMouseListener(this);
addMouseMotionListener(this);
levelspic = Toolkit.getDefaultToolkit().getImage("levelspic.png");
}
public void paintComponent(Graphics g)
{//paint component
super.paintComponent(g);//draw background
g.drawImage(levelspic, 0,0,this);
g.setFont(new Font("Snap ITC", Font.PLAIN, 50));
Color blue = new Color(95,200,255);
if (!integers){
g.setColor(Color.WHITE);
g.fillRect(350,300,300,100);
g.setColor(blue);
g.drawString("Integers",350,375);
}
else{
g.setColor(blue);
g.fillRect(350,300,300,100);
g.setColor(Color.WHITE);
g.drawString("Integers",350,375);
}
if (!addition){
g.setColor(Color.WHITE);
g.fillRect(350,450,300,100);
g.setColor(blue);
g.drawString("Addition",350,525);
}
else{
g.setColor(blue);
g.fillRect(350,450,300,100);
g.setColor(Color.WHITE);
g.drawString("Addition",350,525);
}
g.setFont(new Font("Snap ITC", Font.PLAIN, 45));
if (!subtraction){
g.setColor(Color.WHITE);
g.fillRect(350,600,300,100);
g.setColor(blue);
g.drawString("Subtraction",350,675);
}
else{
g.setColor(blue);
g.fillRect(350,600,300,100);
g.setColor(Color.WHITE);
g.drawString("Subtraction",350,675);
}
}
public void mousePressed(MouseEvent e){}
public void mouseReleased(MouseEvent e){}
public void mouseEntered(MouseEvent e){}
public void mouseExited(MouseEvent e){}
public void mouseClicked(MouseEvent e)
{int mouseX = e.getX();
int mouseY = e.getY();
if(mouseX>= 350 && mouseX <= 650){
if (mouseY>= 300 && mouseY <=400 ){
ccc.show(cP, "p2");
panel2.jc7.panel1.redo();
}
else if (mouseY >= 450 && mouseY <= 550){
panel3.jcAddition.panel1.redo();
ccc.show(cP, "p3");
}
else if (mouseY >= 600 && mouseY <= 700){
panel4.jc.panel1.redo();
ccc.show(cP, "p4");
}
}
}
public void mouseMoved(MouseEvent e)
{
int mouseX = e.getX();
int mouseY = e.getY();
if(mouseX>= 350 && mouseX <= 650){
if (mouseY>= 300 && mouseY <=400 ){
//System.out.println("sselected");
integers = true;
}
else{
//System.out.println("")
integers = false;
}
if (mouseY >= 450 && mouseY <= 550){
addition = true;
}
else{
addition = false;
}
if (mouseY >= 600 && mouseY <= 700){
subtraction = true;
}
else{
subtraction = false;
}
}
else{
addition = false;
integers = false;
subtraction = false;
}
repaint();
}
public void mouseDragged(MouseEvent e){}
}
class Panel2 extends JPanel implements ActionListener{//class Panel 2 is the page where the game starts (at level 1), for now this page will be left blank and later the game code will be added in
private JButton d;//global button
JCOriginal jc7;
Panel2(){
setBackground(Color.GREEN);
repaint();
setLayout(new BorderLayout(5, 5));//set border layout
d= new JButton("Back to Levels");//add button for leading back to home page
d.addActionListener(this);//add listener to button
add(d, BorderLayout.SOUTH); //add button to panel on the bottom
jc7= new JCOriginal();
add(jc7, BorderLayout.CENTER);
}
public void paintComponent(Graphics g)
{//paint component
super.paintComponent(g);//draw background
}
public void actionPerformed (ActionEvent e) { //event handler for button\(actionPreformed)
jc7.panel1.redo();
ccc.show(cP, "p1"); // go back to the front page card
}
}
class Panel3 extends JPanel implements ActionListener{//class Panel 3 is the instructions page. We will use a text area for this
private JButton d;//global button
JCAddition jcAddition;
Panel3(){
setBackground(Color.GREEN);
repaint();
setLayout(new BorderLayout(5, 5));//set border layout
d= new JButton("Back to Levels");//add button for leading back to home page
d.addActionListener(this);//add listener to button
add(d, BorderLayout.SOUTH); //add button to panel on the bottom
jcAddition= new JCAddition();
add(jcAddition, BorderLayout.CENTER);
}
public void paintComponent(Graphics g)
{//paint component
super.paintComponent(g);//draw background
}
public void actionPerformed (ActionEvent e) { //event handler for button\(actionPreformed)
jcAddition.panel1.redo();
ccc.show(cP, "p1"); // go back to the front page card
}
}
class Panel4 extends JPanel implements ActionListener{//class Panel 4 is the credits page, for now this page will be left blank
private JButton d;//global button
JCSubtraction jc;
Panel4(){
setBackground(Color.GREEN);
repaint();
setLayout(new BorderLayout(5, 5));//set border layout
d= new JButton("Back to Levels");//add button for leading back to home page
d.addActionListener(this);//add listener to button
add(d, BorderLayout.SOUTH); //add button to panel on the bottom
jc= new JCSubtraction();
add(jc, BorderLayout.CENTER);
}
public void paintComponent(Graphics g)
{//paint component
super.paintComponent(g);//draw background
System.out.println("Here 1");
}
public void actionPerformed (ActionEvent e) { //event handler for button\(actionPreformed)
jc.panel1.redo();
ccc.show(cP, "p1"); // go back to the front page card
}
}
}