Skip to main content

Cancel Timer together with form close

Please note these java.net forums are being decommissioned and use the new and improved forums at https://community.oracle.com/community/java.
1 reply [Last post]
balafre
Offline
Joined: 2011-02-15
Points: 0

Hello colleagues,
I've faced with the following problem: I have a Timer I initialize and start during the form execution. Then I need to cancel this timer when this form is replaced by some other form. The deal is: how to catch the event of form closure to put timer.cancel() there? Or is there any workaround?
Sure I could put a code into actionPerformed() method of backCommand, but unfortunately form change in my application is not driven by user actions only but also by some events so this solution is not enough.
Thank you in advance for any advice!

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
vprise
Offline
Joined: 2003-11-07
Points: 0

We recommend avoiding the timer and using animations which are invoked on the EDT and are specific to a given form e.g.:

<br />
frm.registerAnimated(myAnimation);<br />

The animate method will be called in every edt cycle, just return false.

Alternatively you can override the initilize/deinitialize methods of any component to discover when a form is active. Notice that a form is deinitialized and re-initialized when a dialog or menu is shown!