Skip to main content

Cancel Timer together with form close

Please note these forums are being decommissioned and use the new and improved forums at
1 reply [Last post]
Joined: 2011-02-15

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.
Joined: 2003-11-07

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!