I'm guessing you are talking about the javax.swing.Timer which basically
"fires" an action event at specific time intervals until the stop() method
is called on it. There is also a java.util.Timer class but that is more
complex. Not for a java novice. Read the API docs on javax.swing.Timer
especially these links which are referenced in those API docs.
"how to" on javax.swing.Timer
http://java.sun.com/docs/books/tutorial/uiswing/misc/timer.html
info on both
http://java.sun.com/products/jfc/tsc/articles/timer/
This is an japplet example that uses javax.swing.Timer
import javax.swing.*;
import java.awt.event.*;
public class MyApplet extends JApplet {
private Timer timer;
private JTextField display;
private int counter=0;
public void init() {
display= new JTextField(10);
getContentPane().add(display);
}
public void start() {
if(timer!=null) {
timer.restart();
} else {
ActionListener timerHandler = new TimerHandler();
//triger the timer event every 1000 milliseconds
timer = new Timer(1000,timerHandler);
}
}
public void stop() {
timer.stop();
}
private class TimerHandler implements ActionListener {
public void actionPerformed(ActionEvent e) {
//this event occurs within the Swing event-handler thread so
//should be safe to modify visible/paintable info of a Swing
class
display.setText("Counter is "+ ++counter);
}
}
}