Search This Blog

Monday, April 24, 2006

Two Timer class : Java

Do you know, Java has two Timer class one in javax.swing.Timer object calls an action listener at regular intervals or only once. It can be used to show frames of an animation many times per second, repaint a clock every second and another class in the java.util package, java.util.Timer, which is better for large timing tasks. It also has more features (eg, it can start at a given time, use either a fixed delay or fixed rate), but javax.swing.Timer is easier to use for simple animations. It is also advisable to use java.util.Timer for headless programs, those without a GUI.

Timer t= new Timer(, );
t.start();
...
t.stop();

No comments: