// This example is from the book _Java Threads_ by Scott Oaks and Henry Wong.
// Written by Scott Oaks and Henry Wong.
// Copyright (c) 1997 O'Reilly & Associates.
// You may study, use, modify, and distribute this example for any purpose.
// This example is provided WITHOUT WARRANTY either expressed or implied.
import java.awt.*;
public class TimerThread extends Thread {
Component comp; // Component that need repainting
int timediff; // Time between repaints of the component
public TimerThread(Component comp, int timediff) {
this.comp = comp;
this.timediff = timediff;
}
public void run() {
while (true) {
try {
comp.repaint();
sleep(timediff);
} catch (Exception e) {}
}
}
}
|