Timer

Timer represents a task that should be run only after a certain time period. Timers are used to schedule tasks such as drawing an animation to the screen. Timer is created by creating a new timer object and setting a new timer listener.

The methods to start and stop the timer are .start and .stop.

The method .is active checks if the timer is active.

.getDelay returns the timer delay in milliseconds.

.setDelay sets a new delay for the timer in milliseconds.

.get recurring method is used to check whether the Timer event calls the Timer repeatedly. The return value is a a boolean value .set recurring sets the Timer event to call Timer either repeatedly or never.

Example: Timer
export main
  System.run application new MyApplication
  
class MyApplication extends Application implements TimerListener

  int n = 0
  
  // Define constantly recurring timer myTimer
  Timer myTimer = new Timer listener this delay 2000 recurring true start true
  
  // Implement interface TimerListener
  timer event <Timer timer>
    screen.repaint
    n++

  // Draw value of 'n' to the screen
  draw to <Canvas c>
    string s = n
    c.clear
    c.draw string s to 0, 0

API Documentation: Class Timer