-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKey 3.java
More file actions
262 lines (227 loc) · 8.45 KB
/
Key 3.java
File metadata and controls
262 lines (227 loc) · 8.45 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
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
/*
Aditi Dantuluri
* 3/12/22
* Key.java
* Week one of game project*/
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.CardLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import java.awt.*;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.ActionEvent;
import java.awt.event.KeyListener;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.time.*;
public class Key extends JFrame {
PredatorKey pc = new PredatorKey();
public static void main (String [] args) {
Key JoeBobKim = new Key();
}
public Key() {
//make start panel
super ("Key");
setSize( 600, 600);
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
setLocation(200,100);
setResizable(true);
JPanel pan = new JPanel();
CardLayout cl = new CardLayout();
pan.setLayout(cl);
Instruction ins = new Instruction();
Start st2 = new Start();
add(ins, "ins");
add(st, "st");
//Start enter = new Start();
setContentPane(pan);
setVisible(true);
}
class PredatorKey extends JPanel {
public PredatorKey() {
PredatorAvtion();
}
public void PredatorAvtion() {
stpanel mp = new stpanel();
gapanel gp = new gapanel();
gp.addKeyListener(new MKeyListener());
gp.setFocusable(true);
gp.requestFocusInWindow();
Settings setting = new Settings();
Instructions instruction = new Instructions();
setLayout(cardLayout1);
add(mp , "Start Screen");
add(gp, "Game Panel");
add(setting, "Settings Panel");
add(instruction, "Instructions Panel");
}
class stpanel extends JPanel {
stpanel() {
setLayout(null);
JButton startButton = new JButton("Play");
startButton.setFont(new Font("Airacobra", Font.BOLD, 30));
add(startButton);
startButton.setBounds(300, 200, 300, 100);
startButton.addActionListener(new sbuttonListener());
JButton settingsButton = new JButton("Settings");
settingsButton.setFont(new Font("Airacobra", Font.BOLD, 30));
add(settingsButton);
settingsButton.setBounds(300, 350, 300, 100);
settingsButton.addActionListener(new sbuttonListener());
JButton instructionsButton = new JButton("Instructions");
instructionsButton.setFont(new Font("Airacobra", Font.BOLD, 30));
add(instructionsButton);
instructionsButton.setBounds(300, 500, 300, 100);
instructionsButton.addActionListener(new sbuttonListener());
}
public void paintComponent(Graphics g) {
super.paintComponent(g);
//Image stickman = new ImageIcon("stickman.jpg").getImage();
Image startPageBackground = new ImageIcon("frontPageBackground.jpg").getImage();
g.drawImage(startPageBackground, 0, 0, 900,900, null);
}
}
class gapanel extends JPanel {
int speed = 20;
gapanel() {
}
o public void paintComponent(Graphics g) {
super.paintComponent(g);
//Image stickman = new ImageIcon("stickman.jpg").getImage();
//Image startPageBackground = new ImageIcon("frontPageBackground.jpg").getImage();
//g.drawImage(startPageBackground, 0, 0, 900,900, null);
Image back = new ImageIcon("firstGame.jpg").getImage();
g.drawImage(back, 0, 0, 900,900, null);
}
}
class Instruction extends JPanel {
public Instruction() {
setLayout(null);
setBackground(new Color( 155, 279, 199));
}
public void paintComponent(Graphics g) {
super.paintComponent(g);
//Image stickman = new ImageIcon("stickman.jpg").getImage();
Image startPageBackground = new ImageIcon("frontPageBackground.jpg").getImage();
}
}
class Play extends JPanel {
public Play() {
setLayout(null);
setBackground(new Color( 255, 179, 199));
}
public void paintComponent(Graphics g) {
super.paintComponent(g);
//Image stickman = new ImageIcon("stickman.jpg").getImage();
Image startPageBackground = new ImageIcon("frontPageBackground.jpg").getImage();
}
}
class Start extends JPanel {
CardLayout cardLayout1 = new CardLayout();
public Start() {
setLayout(null);
setBackground(new Color( 255, 179, 199));
}
public void paintComponent(Graphics g) {
//add in the start panels text introductions and colors
super.paintComponent(g);
g.setColor(Color.RED);
Font sericBold20 = new Font("Luminari",Font.PLAIN,35);
g.setFont(sericBold20);
Listener l = new Listener();
//button.addActionListener(l);
Play playclass = new Play();
g.drawString("WELCOME TO...", 170, 40);
Font predator = new Font("Luminari",Font.BOLD,50);
g.setFont(predator);
g.drawString("Predators Key",87,130);
}
class Listener implements ActionListener {
public void actionPerformed(ActionEvent e) {
}
}
}
class runIt extends JPanel {
public void runIt() {
runit();
}
public void runit() {
//make start button
Instruction instr = new Instruction();
Play play = new Play();
add(instr, "instructions");
add(play, "play");
JPanel panel = new JPanel();
CardLayout cl = new CardLayout();
panel.setLayout(cl);
JButton first = new JButton("start");
first.addActionListener(new sbuttonListener());
first.addActionListener(e -> cl.next(panel));
first.setPreferredSize(new Dimension(600,120));
first.setFont(new Font("Luminari", Font.PLAIN, 30));
first.setOpaque(true);
first.setBackground(Color.RED);
//this is the action listener
first.setBounds(110,180,400,100);
//make instructions button to know how to play game
JButton instructions = new JButton("instructions");
instructions.addActionListener(new sbuttonListener());
//listner
//start1.addActionListener(this);
instructions.setPreferredSize(new Dimension(600,120));
instructions.setFont(new Font("Luminari", Font.PLAIN, 30));
instructions.setOpaque(true);
instructions.setBackground(Color.RED);
instructions.setBounds(110,380,400,100);
add(first);
add(instructions);
//JButton start = new JButton("instructions");
//start.addActionListener(e -> cl.next(panel));
//draw main road obstacles
/* g.setColor(Color.BLUE);
g.fillOval(carX+2, carY, 20, 20); // back wheel
g.fillOval(carX+40, carY, 40, 40); // front wheel
g.fillRect(carX, carY-20, 60, 20); // main body
g.fillRect(carX+10, carY-35, 40, 15); // top
g.setColor(Color.RED); //truck
g.fillOval(carX+2, carY, 20, 20); // back wheel
g.fillOval(carX+40, carY, 40, 40); // front wheel
g.fillRect(carX, carY-20, 60, 20); // main body
g.fillRect(carX+10, carY-35, 40, 15); // top
g.setColor(Color.YELLOW);
g.fillOval(carX+2, carY, 20, 20); // back wheel
g.fillOval(carX+40, carY, 40, 40); // front wheel
g.fillRect(carX, carY-20, 60, 20); // main body
g.fillRect(carX+10, carY-35, 40, 15); // top
g.setColor(Color.PINK);
g.fillOval(carX+2, carY, 20, 20); // back wheel
g.fillOval(carX+40, carY, 40, 40); // front wheel
g.fillRect(carX, carY-20, 60, 20); // main body
g.fillRect(carX+10, carY-35, 40, 15); // top
g.setColor(Color.GREEN);
g.fillOval(carX+2, carY, 20, 20); // back wheel
g.fillOval(carX+40, carY, 40, 40); // front wheel
g.fillRect(carX, carY-20, 60, 20); // main body
*/ //g.fillRect(carX+10, carY-35, 40, 15);//top of car
}
class sbuttonListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
String sbutton = e.getActionCommand();
System.out.println("we are in sbuttonListener");
if(sbutton.equalsIgnoreCase("play")) {
st.cardLayout1.show(st, "st");
System.out.println("play");
} else if(sbutton.equalsIgnoreCase("instructions")) {
st.cardLayout1.show(st, "ins");
System.out.println("instructioons");
}
}
}
}
}
}