-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclicktimer.java
More file actions
220 lines (181 loc) · 4.75 KB
/
clicktimer.java
File metadata and controls
220 lines (181 loc) · 4.75 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
package mayank;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import mayank.menubar.HelpWindow;
public class clicktimer extends JFrame{
private JMenuBar menubar;
private JMenu file,about;
private JMenuItem restart,exit,help;
private JLabel first,entertime,counter,result;
private JTextField tf;
private JButton st,cl;
int count=0;
int timecount;
private Timer timer;
clicktimer(){
super("Click In Time Game");
setLayout(new GridLayout(3,1));
menubar=new JMenuBar();
setJMenuBar(menubar);
file=new JMenu("File");
menubar.add(file);
restart=new JMenuItem("Restart");
exit=new JMenuItem("Exit");
file.add(restart);
file.add(exit);
about=new JMenu("About");
menubar.add(about);
help=new JMenuItem("Help");
about.add(help);
restart r=new restart();
restart.addActionListener(r);
exit e=new exit();
exit.addActionListener(e);
helping h=new helping();
help.addActionListener(h);
Container pane=getContentPane();
JPanel top=new JPanel();
top.setLayout(new GridLayout(1,1));
first=new JLabel("Enter time,pess Start,and press click repeatedly!!",SwingConstants.CENTER);
top.add(first);
pane.add(top);
JPanel middle =new JPanel();
middle.setLayout(new GridLayout(1, 3));
entertime=new JLabel("Enter time->");
tf=new JTextField(10);
tf.selectAll();
st=new JButton("START");
middle.add(entertime);
middle.add(tf);
middle.add(st);
pane.add(middle);
JPanel bottom=new JPanel();
bottom.setLayout(new GridLayout(1, 3));
counter=new JLabel("Counts:0");
result=new JLabel("Time:0");
cl=new JButton("Click");
cl.setEnabled(false);
bottom.add(cl);
bottom.add(counter);
bottom.add(result);
pane.add(bottom);
event ev =new event();
st.addActionListener(ev);
}
public class event implements ActionListener{
public void actionPerformed(ActionEvent e) {
try{
timecount=(int)(Integer.parseInt(tf.getText()));
timer=new Timer(1000,null);
timer.start();
cl.setEnabled(true);
st.setEnabled(false);
result.setText("Time:"+timecount);
timer.addActionListener(
new ActionListener(){
public void actionPerformed(ActionEvent e) {
timecount--;
if(timecount>=1){
result.setText("Time:"+timecount);
}
else if(timecount<1){
timer.stop();
result.setText("Times Up!!");
cl.setEnabled(false);
}
}
}
);
cl.addActionListener(
new ActionListener() {
public void actionPerformed(ActionEvent e) {
count++;
counter.setText("Counts:"+count);
}
}
);
}
catch(NumberFormatException n){
tf.selectAll();
tf.setText("Enter no.s only");
}
}
}
public class helping implements ActionListener{
public void actionPerformed(ActionEvent e) {
helpwindow obj=new helpwindow(clicktimer.this);
obj.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
obj.setSize(500,100);
obj.setResizable(false);
obj.setVisible(true);
}
}
public class helpwindow extends JDialog{
/**
*
*/
private static final long serialVersionUID = 1L;
private JLabel lab;
helpwindow(JFrame framing){
super(framing,"About The Game",true);
lab=new JLabel();
lab.setText("Set the timer and click as much as you can before timer stops!!");
add(lab);
}
}
public class exit implements ActionListener{
public void actionPerformed(ActionEvent e) {
System.exit(0);
}
}
public class restart implements ActionListener{
public void actionPerformed(ActionEvent e) {
urgent ob1=new urgent(clicktimer.this);
ob1.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
ob1.setSize(300,100);
ob1.setResizable(false);
ob1.setVisible(true);
}
}
public class urgent extends JDialog{
JLabel lab;
JButton ok,cancel;
public urgent(JFrame frame){
super(frame,"THINK ONCE!!",true);
getToolkit().beep();
setLayout(new FlowLayout());
lab=new JLabel("Are you sure to restart!!");
add(lab);
ok=new JButton("Ok");
cancel=new JButton("Cancel");
add(ok);
add(cancel);
ok.addActionListener(
new ActionListener(){
public void actionPerformed(ActionEvent e) {
st.setEnabled(true);
cl.setEnabled(false);
counter.setText("Counts:0");
result.setText("Time:0");
tf.setText("");
dispose();
}
}
);
cancel.addActionListener(
new ActionListener(){
public void actionPerformed(ActionEvent e) {
dispose();
}
}
);
}
}
public static void main(String[] args) {
clicktimer ob=new clicktimer();
ob.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
ob.setVisible(true);
ob.setSize(500,200);
}
}