Java Timer in GWT

依然范特西╮ 提交于 2019-11-29 14:33:52

If you're using Libgdx, you can use the libgdx Timer infrastructure to schedule work to run in the future:

Timer t = new Timer();
t.scheduleTask(new Timer.Task() { 
      public void run() { /* some code */ } 
  }), /* Note that libgdx uses float seconds, not integer milliseconds: */ 5);

This way you can schedule the timer in your platform independent code. (The GWT-specific solution will only work in the platform dependent part of your project.)

Suresh Atta

In GWT you are restricted to use all the Util package classes.

Here is the List of Classes only you can use from util class.

You can use GWT Timer class.

Example(from docs);

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

    // Schedule the timer to run once in 5 seconds.
    t.schedule(5000);
  }
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!