Class Timer

Constructors

Methods

See Also

TimerListener

(Timer) new Timer listener <TimerListener listener> [delay <int timerDelay = 500>] [recurring <bool recurringTimer = false>] [start <bool startNow = false>]

Creates a new Timer. The timer is started if the startNow parameter is true, otherwise the timer should be started separately. Timer delays are represented in milliseconds. If the timer is recurring, the timer listener's timer event method will be called periodically until the timer is stopped.

Parameters

Exceptions

Example

main
  system.run application new MyApplication
                
class MyApplication extends Application implements TimerListener
  // Construct and start a new recurring timer with 1s delay.
  Timer t = new Timer listener this delay 1000 recurring true start true

  timer event <Timer caller>
    print "Timer expired"
                

start

Starts the timer.

Example

main
  system.run application new MyApplication
                
class MyApplication extends Application implements TimerListener
  // Construct a new recurring timer with 1s delay.
  Timer t = new Timer listener this delay 1000 recurring true
  
  MyApplication
    t.start

  timer event <Timer caller>
    print "Timer expired"
                

stop

Stops the timer.

Example

main
  system.run application new MyApplication
                
class MyApplication extends Application implements TimerListener
  // Construct and start a new recurring timer with 1s delay.
  Timer t = new Timer listener this delay 1000 recurring true start true

  timer event <Timer caller>
    print "Timer expired"
    t.stop
    print "Timer stopped"
                

set delay <int newDelay>

Sets a new Delay for the timer. The timer is not re-started, but the timeout is updated on the fly.

Parameters

Example

main
  system.run application new MyApplication
                
class MyApplication extends Application implements TimerListener
  // Construct and start a new recurring timer with 1s delay.
  Timer t = new Timer listener this delay 1000 recurring true start true

  timer event <Timer caller>
    print "Timer expired"
    // Increase delay by one second
    t.set delay (t.get delay + 1000)
                

(int) get delay

Returns the delay of the timer

Return value

Example

main
  system.run application new MyApplication
                
class MyApplication extends Application implements TimerListener
  // Construct and start a new recurring timer with 1s delay.
  Timer t = new Timer listener this delay 1000 recurring true start true
  
  MyApplication
    int currentDelay = t.get delay        // currentDelay == 1000

  timer event <Timer caller>
    print "Timer expired"
                

(bool) get recurring

Returns true if the timer is recurring

Return value

Example

main
  system.run application new MyApplication
                
class MyApplication extends Application implements TimerListener
  // Construct and start a new recurring timer with 1s delay.
  Timer t = new Timer listener this delay 1000 recurring true start true
  
  MyApplication
    bool recurring = t.is recurring        // recurring == true

  timer event <Timer caller>
    print "Timer expired"
                

set recurring <bool recurring>

Parameters

Example

main
  system.run application new MyApplication
                
class MyApplication extends Application implements TimerListener
  // Construct and start a new recurring timer with 1s delay.
  Timer t = new Timer listener this delay 1000 recurring true start true
  
  MyApplication
    bool recurring = t.is recurring        // recurring == true
    // Change recurrence
    t.set recurring (not recurring)

  timer event <Timer caller>
    print "Timer expired"
                

(bool) is active

Returns true if the timer is active, that is, it has been started.

Return value

Example

main
  system.run application new MyApplication
                
class MyApplication extends Application implements TimerListener
  // Construct and start a new recurring timer with 1s delay.
  Timer t = new Timer listener this delay 1000 start true

  timer event <Timer caller>
    print "Timer expired"

    // Will output "Timer is not active"
    if ( t.is active )
      print "Timer is active"
    else
      print "Timer is not active"