Use Swing Timer class in Java
Description
The following code shows how to use Swing Timer class.
A Timer object will send an ActionEvent to the registered ActionListener.
Example
/* w ww .j a va 2 s.c om*/
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.Timer;
public class Main implements ActionListener {
Timer t = new Timer(1000, this);
Main() {
t.start();
}
public void actionPerformed(ActionEvent e) {
System.out.println("working");
}
public static void main(String args[]) {
Main main = new Main();
}
}
Home »
Java Tutorial »
Swing »
Java Tutorial »
Swing »