-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathClock.java
68 lines (57 loc) · 1.06 KB
/
Clock.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Observable;
import javax.swing.Timer;
public class Clock extends Observable implements ActionListener{
private int minutes;
private int seconds;
private int centis;
private Timer timer;
public static final int INTERVAL = 10;
public Clock() {
minutes = 0;
seconds = 0;
centis = 0;
timer = new Timer(INTERVAL, this);
}
public int getMinutes() {
return minutes;
}
public int getSeconds() {
return seconds;
}
public int getCentis() {
return centis;
}
public void start() {
timer.start();
}
public void stop() {
timer.stop();
}
public Time getTime() {
return new Time(minutes, seconds, centis);
}
public void reset() {
timer.stop();
minutes = 0;
seconds = 0;
centis = 0;
setChanged();
notifyObservers();
}
public void actionPerformed(ActionEvent e){
centis++;
if(centis >= 100) {
seconds++;
centis -= 100;
if(seconds >= 60)
{
minutes++;
seconds -= 60;
}
}
setChanged();
notifyObservers();
}
}