Class Timer

java.lang.Object
com.google.gwt.user.client.Timer

public abstract class Timer extends Object
A simplified, browser-safe timer class. This class serves the same purpose as java.util.Timer, but is simplified because of the single-threaded environment.

To schedule a timer, simply create a subclass of it (overriding run()) and call schedule(int) or scheduleRepeating(int).

NOTE: If you are using a timer to schedule a UI animation, use AnimationScheduler instead. The browser can optimize your animation for maximum performance.

Example

public class TimerExample implements EntryPoint, ClickHandler {

  public void onModuleLoad() {
    Button b = new Button("Click and wait 5 seconds");
    b.addClickHandler(this);

    RootPanel.get().add(b);
  }

  public void onClick(ClickEvent event) {
    // Create a new timer that calls Window.alert().
    Timer t = new Timer() {
      @Override
      public void run() {
        Window.alert("Nifty, eh?");
      }
    };

    // Schedule the timer to run once in 5 seconds.
    t.schedule(5000);
  }
}