Java Timer in GWT

I am trying to use Java Timer in my EntryPoint:

Timer timer = new Timer(); timer.schedule( new TimerTask() { public void run() { //some code } } , 5000); 

But when I tried to compile this, I got: No source code for type java.util.Timer ; did you forget to inherit the required module?

What can I do to fix this error?

+4
source share
2 answers

If you are using Libgdx, you can use the libgdx Timer framework to schedule future work:

 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 a timer in your platform-independent code. (A GWT-specific solution will only work in the platform-specific part of your project.)

+5
source

In GWT, you can use all classes of the Util package.

Here is a list of classes that you can only use from the util class.

You can use the GWT timer class .

Example (from documents);

  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); } 
+12
source

All Articles