O'Reilly logo

Java™ ME Game Programming, Second Edition by Ph.D. Martin J. Wells, Ph.D. John P. Flynt

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Using Timer and TimerTask Objects

A Timer object enables you to schedule tasks for execution. It makes use of a background application thread, and the tasks that you schedule using it can execute either once or multiple times at determined intervals. You can implement several Timer objects in a given MIDlet. Each Timer object has its own thread within the application. The Timer class is supported by the TimerTask class, which allows you to specify tasks. Both of these classes are in the java.util package, as Table 7.1 indicates. Two exceptions are associated with Timer methods. One of these is the IllegalArgumentException, which indicates that the period or delay assigned to a task is negative. Another is the IllegalStateException, which indicates ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required