|
How to implement actions that listens to events from a Timer |
|
|
This Java Swing tip illustrates a metod of implementing actions that
listens to events from a Timer. This tip is an extension of the JLabel
class that listens to events from a Timer object to update itself with
the current date & time.
import java.util.Date;
import java.awt.event.*;
import javax.swing.*;
public class ClockLabel extends JLabel implements ActionListener {
public ClockLabel() {
super("" + new Date());
Timer t = new Timer(1000, this);
t.start();
}
public void actionPerformed(ActionEvent ae) {
setText((new Date()).toString());
}
}
|
Related Tips
|
Page 1 of 0 ( 0 comments )
You can share your information about this topic using the form below!
Please do not post your questions with this form! Thanks.