home *** CD-ROM | disk | FTP | other *** search
- import java.awt.Component;
- import java.awt.Event;
-
- public class Timer implements Runnable {
- Component target;
- int eventType;
- boolean repeat;
- boolean repeating;
- boolean execute;
- Thread thread;
- int delay;
-
- public Timer(Component t) {
- this(t, 1000);
- }
-
- public Timer(Component t, int d) {
- this(t, d, false);
- }
-
- public Timer(Component t, int d, boolean r) {
- this(t, d, r, 1001);
- }
-
- public Timer(Component t, int d, boolean r, int e) {
- this.target = t;
- this.delay = d;
- this.repeat = r;
- this.execute = false;
- this.thread = new Thread(this);
- this.eventType = e;
- this.thread.start();
- }
-
- public void setEventType(int type) {
- this.eventType = type;
- }
-
- public int getEventType() {
- return this.eventType;
- }
-
- public void setTarget(Component t) {
- this.target = t;
- }
-
- public Component getTarget() {
- return this.target;
- }
-
- public void setDelay(int d) {
- this.delay = d;
- }
-
- public int getDelay() {
- return this.delay;
- }
-
- public void start() {
- this.execute = true;
- this.thread.resume();
- }
-
- public void setRepeat(boolean f) {
- this.repeat = f;
- }
-
- public boolean getRepeat() {
- return this.repeat;
- }
-
- public void start(int d) {
- this.delay = d;
- this.start();
- }
-
- public void start(boolean r) {
- this.repeat = r;
- this.start();
- }
-
- public void start(int d, boolean r) {
- this.delay = d;
- this.repeat = r;
- this.start();
- }
-
- public void stop() {
- this.execute = false;
- this.repeating = false;
- }
-
- public void run() {
- if (!this.execute) {
- this.thread.suspend();
- }
-
- try {
- while(true) {
- this.repeating = this.repeat;
-
- do {
- Thread.sleep((long)this.delay);
- if (this.execute) {
- this.target.handleEvent(new Event(this, this.eventType, (Object)null));
- }
- } while(this.repeating);
-
- this.thread.suspend();
- }
- } catch (InterruptedException var1) {
- }
- }
- }
-