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
- listener - Listener object that will receive the timer events.
- timerDelay - Delay of the timer in milliseconds.
- recurringTimer - If true, timer is recurring.
- startNow - If true, the timer is started right away..
Exceptions
- NullPointerException - If the listener is null.
- InvalidArgumentException - If the timerDelay is negative.
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.
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.
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
- newDelay - New value for the delay of the timer.
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
- Delay of the timer in milliseconds.
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
- True if the timer is a recurring timer.
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
- recurring - Sets the timer recurring.
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
- True if the timer is active.
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"