-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMyTimer.java
44 lines (33 loc) · 1.01 KB
/
MyTimer.java
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
package timer;
import java.awt.event.*;
import java.awt.*;
import javax.swing.*;
public class MyTimer {
Timer timer;
int timeLimit = 10;
int currentTime;
public MyTimer() {
}
public int getCurrentTime(){
return currentTime;
}
public void updateCurrentTime(){
final JFrame frame = new JFrame("Timer");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
final JLabel label = new JLabel(Integer.toString(timeLimit));
JPanel panel = new JPanel();
panel.add(label, BorderLayout.SOUTH);
frame.getContentPane().add(panel);
frame.pack();
frame.setVisible(true);
timer = new Timer(1000, new ActionListener() {
public void actionPerformed(ActionEvent e) {
label.setText(String.valueOf(timeLimit));
timeLimit--;
if (timeLimit == 0) {
timer.stop();
}
}
});timer.start();
}
}