-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJCMain.java
More file actions
244 lines (211 loc) · 8.07 KB
/
JCMain.java
File metadata and controls
244 lines (211 loc) · 8.07 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
243
244
//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.*;
import java.util.Scanner;
public class JCMain extends JApplet//jframe
{
Panel1 panel1= new Panel1();
Panel2 panel2= new Panel2();
Panel3 panel3= new Panel3();
Panel4 panel4= new Panel4();
CardPages cP;
CardLayout ccc;
//private boolean booleanV=false;
public void init()//main
{
cP = new CardPages(); // object for pages CardLayout class
setContentPane(cP);
}
public JCMain()//constructor
{
// add CardLayout object to the container
}
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 i;
private Image start;
private Image startselected;
private Image instructions;
private Image instructionsselected;
private Image credits;
private Image creditsselected;
private boolean sselected = false;
private boolean iselected = false;
private boolean cselected = false;
public Panel1()
{
setLayout(new GridLayout(4,1, 10, 10));
i = Toolkit.getDefaultToolkit().getImage("menupic.png");
start = Toolkit.getDefaultToolkit().getImage("start.png");
startselected= Toolkit.getDefaultToolkit().getImage("startselected.png");
instructions = Toolkit.getDefaultToolkit().getImage("instructions.png");
instructionsselected = Toolkit.getDefaultToolkit().getImage("instructionsselected.png");
credits = Toolkit.getDefaultToolkit().getImage("credits.png");
creditsselected = Toolkit.getDefaultToolkit().getImage("creditsselected.png");
addMouseListener(this);
addMouseMotionListener(this);
}
public void paintComponent(Graphics g)
{//paint component
//super.paintComponent(g);//draw background
g.drawImage(i, 0,0,1000,800,this);
if (sselected){
g.drawImage(startselected, 350,300,this);
}
else{
g.drawImage(start, 350,300,this);
}
if(iselected){
g.drawImage(instructionsselected, 350,450,this);
}
else{
g.drawImage(instructions, 350,450,this);
}
if(cselected){
g.drawImage(creditsselected, 350,600,this);
}
else{
g.drawImage(credits, 350,600,this);
}
}
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.jc.panel2.jc7.panel1.redo();
panel2.jc.panel4.jc.panel1.redo();
panel2.jc.panel3.jcAddition.panel1.redo();
}
else if (mouseY >= 450 && mouseY <= 550){
ccc.show(cP, "p3");
}
else if (mouseY >= 600 && mouseY <= 700){
ccc.show(cP, "p4");
}
}
}
public void mouseReleased(MouseEvent e){}
public void mousePressed(MouseEvent e){}
public void mouseEntered(MouseEvent e){}
public void mouseExited(MouseEvent e){}
public void mouseDragged(MouseEvent e){}
public void mouseMoved(MouseEvent e){
// System.out.println("mousemoved");
int mouseX = e.getX();
int mouseY = e.getY();
if(mouseX>= 350 && mouseX <= 650){
if (mouseY>= 300 && mouseY <=400 ){
//System.out.println("sselected");
sselected = true;
}
else{
//System.out.println("")
sselected = false;
}
if (mouseY >= 450 && mouseY <= 550){
iselected = true;
}
else{
iselected = false;
}
if (mouseY >= 600 && mouseY <= 700){
cselected = true;
}
else{
cselected = false;
}
}
else{
sselected = false;
iselected = false;
cselected = false;
}
repaint();
}
}
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
JCLevels jc;
Panel2(){
setBackground(Color.GREEN);
repaint();
setLayout(new BorderLayout(5, 5));//set border layout
d= new JButton("Back to Home Page");//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 JCLevels();
add(jc, BorderLayout.CENTER);
}
public void paintComponent(Graphics g)
{//paint component
super.paintComponent(g);//draw background
Font f= new Font("Serif", Font.BOLD, 80);//set font serif to bold and size 40
g.setColor(Color.BLACK);
g.drawString("Game under Construction", 50, 90);
}
public void actionPerformed (ActionEvent e) { //event handler for button\(actionPreformed)
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 dd;
private JTextArea ta;
Panel3(){
setBackground(Color.RED);
repaint();
setLayout(new BorderLayout(5, 5));//set border layout
dd= new JButton("Back to Home Page");//add button for leading back to home page
dd.addActionListener(this);//add listener to button
add(dd, BorderLayout.SOUTH); //add button to panel on the bottom
ta=new JTextArea("Welcome to Bubbles! The game is very simple. You are a red bubble, all other bubbles are blue. You must avoid all bubbles whose values are greater than you, and eat all bubbles whose values are less than you. When you eat a smaller bubble, your value will combine with the eaten bubble, causing you to grow bigger and bigger. You have thirty seconds to eat as much bubbles as you can, but if you get eaten by a bigger bubble, you die right there. Try to get a high score!");
ta.setLineWrap(true);
add(ta, BorderLayout.CENTER);
}
public void paintComponent(Graphics g)
{//paint component
setBackground(Color.RED);
super.paintComponent(g);//draw background
}
public void actionPerformed (ActionEvent e) { //event handler for button\(actionPreformed)
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 ddd;
Panel4(){
setBackground(Color.BLUE);
repaint();
setLayout(new BorderLayout(0,0));//set border layout
ddd= new JButton("Back to Home Page");//add button for leading back to home page
ddd.addActionListener(this);//add listener to button
add(ddd, BorderLayout.SOUTH); //add button to panel on the bottom
}
public void paintComponent(Graphics g)
{//paint component
super.paintComponent(g);//draw background
Font f= new Font("Serif", Font.BOLD, 80);//set font serif to bold and size 40
g.setColor(Color.BLACK);
g.drawString("Credits Page under Construction", 50, 90);
}
public void actionPerformed (ActionEvent e) { //event handler for button\(actionPreformed)
ccc.show(cP, "p1"); // go back to the front page card
}
}
}