forked from phu004/JavaRTS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTicker.java
More file actions
78 lines (63 loc) · 1.37 KB
/
Copy pathTicker.java
File metadata and controls
78 lines (63 loc) · 1.37 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
package core;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class Ticker implements Runnable{
ActionListener al;
private boolean isTicking;
Thread t;
int delay;
public Ticker(int i, ActionListener actionlistener){
al = actionlistener;
delay = i;
t = new Thread(this);
t.start();
isTicking = false;
}
public Ticker(int i){
delay = i;
t = new Thread(this);
t.start();
isTicking = false;
}
public void addActionListener(ActionListener actionlistener){
if(al == null)
al = actionlistener;
else
System.out.println("WARNING: ActionListener already added to Ticker.");
}
public boolean isRunning(){
return isTicking;
}
public void start(){
isTicking = true;
}
public void stop() {
isTicking = false;
}
public void setDelay(int i){
delay = i;
}
public int getDelay(){
return delay;
}
private void fireActionPerformed(){
if(al == null || !isTicking){
return;
} else{
ActionEvent actionevent = new ActionEvent(this, 0, null);
al.actionPerformed(actionevent);
return;
}
}
public void run(){
do{
fireActionPerformed();
try{
Thread.sleep(delay);
}
catch(InterruptedException interruptedexception){
System.out.println("WARNING: Ticker thread interrupted.");
}
} while(true);
}
}