Scratch for Java

Timer

The Timer class provides methods for timing events in a graphical application. It allows checking if a specified number of milliseconds has passed since the last time a method was called, or if a specified interval has passed.

Usage example:

Timer timer = new Timer();
if (timer.everyMillis(1000)) {
  // Do something every second
}
if (timer.forMillis(5000)) {
  // Do something for 5 seconds
}
if (timer.afterMillis(2000)) {
  // Do something after 2 seconds
}
if (timer.intervalMillis(1000)) {
  // Do something every second
}
Timer