-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathJFTimer.java
More file actions
executable file
·63 lines (49 loc) · 1.05 KB
/
Copy pathJFTimer.java
File metadata and controls
executable file
·63 lines (49 loc) · 1.05 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
package javaforce;
import javaforce.*;
import java.util.Timer;
import java.util.TimerTask;
/**
* A simpler to use Timer, that uses a callback interface.
*
* @see TimerEvent
* @author Peter Quiring
*/
public class JFTimer {
private Timer timer;
private TimerEvent timerevent = null;
private class timertask extends TimerTask {
private JFTimer jftimer;
public timertask(JFTimer t) {
jftimer = t;
}
public void run() {
timerevent.timerEvent(jftimer);
}
}
public JFTimer() {
}
public JFTimer(TimerEvent eh) {
timerevent = eh;
}
public void setTimerEvent(TimerEvent eh) {
timerevent = eh;
}
public void start(long delay) {
if (timer != null) {
stop();
}
timer = new java.util.Timer();
timer.schedule(new timertask(this), delay, delay);
}
public void startOneTime(long delay) {
if (timer != null) {
stop();
}
timer = new java.util.Timer();
timer.schedule(new timertask(this), delay);
}
public void stop() {
timer.cancel();
timer = null;
}
}