Many events generated by a graphical application are events are caused by a user such as mouse events or typing in a textbox, etc.
In contrast, a program can generate regular timer events by creating a Timer instance.
ActionListener listener = ... final int DELAY = 100; // Milliseconds between timer ticks Timer t = new Timer(DELAY, listener); t.start();
-
The second parameter is the object with the event handler code to be executed each time the timer event occurs.
-
Once the timer is started - t.start() - it will generate a timer event after DELAY milliseconds and reset the the timer.
So timer events will continue to occur once every DELAY milliseconds.
-
The timer can be stopped: t.stop()