previous |
start |
next
Processing Timer Events
- javax.swing.Timer generates equally spaced timer
events
- Sends events to action listener
public interface ActionListener
{
void actionPerformed(ActionEvent
event);
}
- Realize the interface
class MyListener implements ActionListener
{
void actionPerformed(ActionEvent
event);
{
// this action will be executed at each timer
event
place listener action here
}
}
- Add listener to timer
MyListener listener = new MyListener();
Timer t = new Timer(interval, listener);
t.start();
previous |
start |
next