-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlast.java
More file actions
280 lines (254 loc) · 7.27 KB
/
last.java
File metadata and controls
280 lines (254 loc) · 7.27 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
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
import java.awt.*;
import java.util.Random;
import java.util.ArrayList;
import java .util.List;
import java.awt.event.*;
import javax.swing.*;
import java.net.URL;
class last extends Frame implements ActionListener,WindowListener
{
int ran1,c;
static int level=1;
List<Integer> arr=new ArrayList<>();
URL blinklast=this.getClass().getResource("mypack\\blinklast.jpg");
Icon blinkk = new ImageIcon(blinklast);
public last()
{
setVisible(true);
setTitle("Memorizing Blocks");
addWindowListener(this);
//Dimension s=Toolkit.getDefaultToolkit().getScreenSize();
//setDefaultCloseOperation(Frame.DISPOSE_ON_CLOSE);
setBounds(100,100,1200,850);
setLocationRelativeTo(null);
setLayout(null);
setResizable(false);
create();
}
Button start,b1,b2,b3,b4,b5,b6,b7,b8,b9,close;
JLabel l1,l2;
public void create()
{
l1=new JLabel();
l1.setForeground(Color.WHITE);
l2=new JLabel();
l2.setIcon(blinkk);
start =new Button("START");
b1=new Button(); b2=new Button(); b3=new Button();
b4=new Button(); b5=new Button(); b6=new Button();
b7=new Button(); b8=new Button(); b9=new Button();
close=new Button("I QUIT");
l1.setHorizontalAlignment(SwingConstants.RIGHT);
l1.setHorizontalTextPosition(SwingConstants.LEFT);
l1.setFont(new Font("Algerian", 2, 48));
l2.setHorizontalAlignment(SwingConstants.CENTER);
l2.setVerticalAlignment(SwingConstants.CENTER);
l2.setBounds(10,10,1200,850);
start.setBounds(100,50,100,50); l1.setBounds(150,50,600,50);
b1.setBounds(200,160,200,200); b2.setBounds(420,160,200,200); b3.setBounds(640,160,200,200);
b4.setBounds(200,380,200,200); b5.setBounds(420,380,200,200); b6.setBounds(640,380,200,200); close.setBounds(860,380,100,100);
b7.setBounds(200,600,200,200); b8.setBounds(420,600,200,200); b9.setBounds(640,600,200,200);
start.addActionListener(this);
close.addActionListener(this);
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
b4.addActionListener(this);
b5.addActionListener(this);
b6.addActionListener(this);
b7.addActionListener(this);
b8.addActionListener(this);
b9.addActionListener(this);
add(b1);
add(b2);
add(b3);
add(b4);
add(b5);
add(b6);
add(b7);
add(b8);
add(b9);
add(start);
add(close);
add(l1);
add(l2);
}
public void windowClosing(WindowEvent we)
{
//System.exit(0);
dispose();
}
public void windowClosed(WindowEvent we)
{}
public void windowOpened(WindowEvent we)
{}
public void windowActivated(WindowEvent we)
{}
public void windowDeactivated(WindowEvent we)
{}
public void windowIconified(WindowEvent we)
{}
public void windowDeiconified(WindowEvent we)
{}
public void clear()
{
arr.clear();
c=0;
b9.setBackground(new java.awt.Color(240, 240, 240));
b1.setBackground(new java.awt.Color(240, 240, 240));
b2.setBackground(new java.awt.Color(240, 240, 240));
b3.setBackground(new java.awt.Color(240, 240, 240));
b4.setBackground(new java.awt.Color(240, 240, 240));
b5.setBackground(new java.awt.Color(240, 240, 240));
b6.setBackground(new java.awt.Color(240, 240, 240));
b7.setBackground(new java.awt.Color(240, 240, 240));
b8.setBackground(new java.awt.Color(240, 240, 240));
}
public void game()
{
clear();
l1.setText("Level : "+level);
int s;
for(s=0; s<=level-1;s++)
{
Random ran=new Random();
ran1=ran.nextInt(9)+1;
blink(ran1);
arr.add(ran1);
}
JOptionPane.showMessageDialog(null, "Your turn");
}
public void sleep(int time)
{
try
{
Thread.sleep(time);
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null,e);
}
}
public void blink(int x)
{
switch(x)
{
case 1:b1.setBackground(new java.awt.Color(0, 0, 0));
break;
case 2:b2.setBackground(new java.awt.Color(0, 0, 0));
break;
case 3:b3.setBackground(new java.awt.Color(0, 0, 0));
break;
case 4:b4.setBackground(new java.awt.Color(0, 0, 0));
break;
case 5:b5.setBackground(new java.awt.Color(0, 0, 0));
break;
case 6:b6.setBackground(new java.awt.Color(0, 0, 0));
break;
case 7:b7.setBackground(new java.awt.Color(0, 0, 0));
break;
case 8:b8.setBackground(new java.awt.Color(0, 0, 0));
break;
case 9:b9.setBackground(new java.awt.Color(0, 0, 0));
break;
}
sleep(300);
switch(x)
{
case 1:b1.setBackground(new java.awt.Color(240, 240, 240));
break;
case 2:b2.setBackground(new java.awt.Color(240, 240, 240));
break;
case 3:b3.setBackground(new java.awt.Color(240, 240, 240));
break;
case 4:b4.setBackground(new java.awt.Color(240, 240, 240));
break;
case 5:b5.setBackground(new java.awt.Color(240, 240, 240));
break;
case 6:b6.setBackground(new java.awt.Color(240, 240, 240));
break;
case 7:b7.setBackground(new java.awt.Color(240, 240, 240));
break;
case 8:b8.setBackground(new java.awt.Color(240, 240, 240));
break;
case 9:b9.setBackground(new java.awt.Color(240, 240, 240));
break;
}
sleep(100);
}
public void user(int x,int y)
{
if(arr.get(y-1)==x && y<=level )
{
blink(x);
if(y==level)
{
JOptionPane.showMessageDialog(null,"You Succeded to Next Level.");
level=level+1;
game();
}
}
else
{
JOptionPane.showMessageDialog(null," GAME OVER.Your score is = "+(level-1));
level=1;
dispose();
}
}
public void actionPerformed(ActionEvent ae)
{
if(ae.getSource()==start)
{
game();
}
else if(ae.getSource()==close)
{
JOptionPane.showMessageDialog(null,"Your High Score = "+(level-1));
My2 m=new My2();
this.dispose();
}
else if(ae.getSource()==b1)
{
user(1,++c);
}
else if(ae.getSource()==b2)
{
user(2,++c);
}
else if(ae.getSource()==b3)
{
user(3,++c);
}
else if(ae.getSource()==b4)
{
user(4,++c);
}
else if(ae.getSource()==b5)
{
user(5,++c);
}
else if(ae.getSource()==b6)
{
user(6,++c);
}
else if(ae.getSource()==b7)
{
user(7,++c);
}
else if(ae.getSource()==b8)
{
user(8,++c);
}
else if(ae.getSource()==b9)
{
user(9,++c);
}
}
}
/*class last
{
public static void main(String args[])
{
last1 ok=new last1();
}
}*/