| Author |
Adding a delay in a java app
|
Jennifer Sohl
Ranch Hand
Joined: Feb 28, 2001
Posts: 455
|
|
I have an application that I want to be able to reset to a different panel (using card layout) if there hasn't been any activity for a certain amount of time. (Kinda like when windows hasn't been used for a while, it goes to a screensaver) How can I tell if there has been no activity? I'm really not sure where to start on this one? Thanks for any help!
|
 |
Stan James
(instanceof Sidekick)
Ranch Hand
Joined: Jan 29, 2003
Posts: 8791
|
|
You might use Timer to schedule a command for n seconds in the future. The command would flip to the other card. That part's easy. Detecting activity might be tough. Anything that counted as "activity" would have to be coded to cancel or restart the Timer. Could be a lot of check points. I use a single actionlistener for all the widgets on my page. If those widgets were the only things that counted as activity then the actionlistener could reset the timer. But there are a lot of things like entry fields that are not hooked to the listener. Any other ideas?
|
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
|
 |
Julian Kennedy
Ranch Hand
Joined: Aug 02, 2004
Posts: 823
|
|
Do Swing events propagate up through the containment hierarchy? If so you could just have an action listener at the root (JFrame or whatever) that reset the SwingTimer if it registered any activity. Of course that may be a very naive suggestion and I haven't checked any manuals... Jules
|
 |
 |
|
|
subject: Adding a delay in a java app
|
|
|