This week's book giveaway is in the General Computing forum.
We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line!
See this thread for details.
The moose likes Java in General and the fly likes Adding a delay in a java app Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "Adding a delay in a java app" Watch "Adding a delay in a java app" New topic
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
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Adding a delay in a java app
 
Similar Threads
Finish any previous activity in stack from current activity?
Execute commands in a sequance with RunTime.getRuntime().exec(cmd)
Marcus Mock Exam 3- Q44
Moderator behavior
When the customer gets demanding :)