Class WTimer

java.lang.Object
eu.webtoolkit.jwt.WObject
eu.webtoolkit.jwt.WTimer

public class WTimer
extends WObject
A utility class which provides timer signals and single-shot timers.

To use a timer, create a WTimer instance, set the timer interval using setInterval() and connect a slot to the timeout signal. Then, start the timer using start(). An active timer may be cancelled at any time using stop().

By default, a timer will continue to generate events until you stop() it. To create a timer that will fire only once, use setSingleShot().

When connecting stateless slot implementations to the timeout signal, these stateless slot implementations will be used as for any other signal (when Ajax is available).

In clients without (enabled) JavaScript support, the minimum resolution of the timer is one second (1000 milli-seconds), and it is probably wise to use timers sparingly.

A WTimer is only usable inside of a JWt event loop. If you want to create a timer outside the JWt event loop, take a look at Timer.

  • Nested Class Summary

    Nested classes/interfaces inherited from class eu.webtoolkit.jwt.WObject

    WObject.FormData
  • Constructor Summary

    Constructors
    Constructor Description
    WTimer()
    Construct a new timer with the given parent.
    WTimer​(WObject parent)
    Construct a new timer with the given parent.
  • Method Summary

    Modifier and Type Method Description
    int getInterval()
    Returns the interval (msec).
    boolean isActive()
    Returns if the timer is running.
    boolean isSingleShot()
    Is this timer set to fire only once.
    void setInterval​(int msec)
    Sets the interval (msec).
    void setSingleShot​(boolean singleShot)
    Configures this timer to fire only once.
    void start()
    Starts the timer.
    void stop()
    Stops the timer.
    EventSignal1<WMouseEvent> timeout()
    Signal emitted when the timer timeouts.

    Methods inherited from class eu.webtoolkit.jwt.WObject

    addChild, getId, getObjectName, remove, setFormData, setObjectName, tr

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • WTimer

      public WTimer​(WObject parent)
      Construct a new timer with the given parent.
    • WTimer

      public WTimer()
      Construct a new timer with the given parent.

      Calls this((WObject)null)

  • Method Details

    • getInterval

      public int getInterval()
      Returns the interval (msec).
    • setInterval

      public void setInterval​(int msec)
      Sets the interval (msec).
    • isActive

      public boolean isActive()
      Returns if the timer is running.
    • isSingleShot

      public boolean isSingleShot()
      Is this timer set to fire only once.
    • setSingleShot

      public void setSingleShot​(boolean singleShot)
      Configures this timer to fire only once.

      A Timer is by default not single shot, and will fire continuously, until it is stopped.

    • start

      public void start()
      Starts the timer.

      The timer will be isActive(), until either the interval has elapsed, after which the timeout signal is activated, or until stop() is called.

    • stop

      public void stop()
      Stops the timer.

      You may stop the timer during its timeout(), or cancel a running timer at any other time.

      See Also:
      start()
    • timeout

      public EventSignal1<WMouseEvent> timeout()
      Signal emitted when the timer timeouts.

      The WMouseEvent does not provide any meaningful information but is an implementation artefact.