The javax.swing.Timer class is a source component that can trigger ActionEvent at a predetermined interval. Listeners to this class needs to implement ActionListener. Listener can be added in the constructor of the Timer class or more listeners can be added using the addActionListener method on the class. Also the delay/interval can be adjusted at a later point of time using the setDelay method. Timer is started using the start() and stopped using the stop methods.
Exercise: Write a program that demonstrates javax.swing.Timer class where a message moves across a panel at an interval of 1 second.
Download Code: Moving Message with Timer
No comments:
Post a Comment