import java.util.Timer;
import java.util.TimerTask;
public class TimerTest {
public TimerTest() {
getTimer().scheduleAtFixedRate(
new TimerTask() {
@Override
public void run() {
System.out.println("It has been 5 seconds.");
}
},
5000, 5000);
}
public static void main(String[] args) {
new TimerTest();
}
public Timer getTimer() {
return timer;
}
private Timer timer = new Timer();
}
The timer will wait 5 seconds, then display the message, then continuously wait 5 seconds and display the message over and over again. I actually think this is kind of cool since I didn't know about it before.Documentation: http://java.sun.com/...util/Timer.html
http://java.sun.com/j2se/1.4.2/docs/api/ja.../TimerTask.html














