File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Automatically closing windows after time Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Automatically closing windows after time" Watch "Automatically closing windows after time" New topic

Automatically closing windows after time

Jo Cook

Joined: Mar 20, 2002
Posts: 2
I just recently passed my Java Prog Cert but still consider myself a beginner since most of my work has been theoretical until now...
I am trying to build a small standalone app that pops up a frame every 30 minutes with a reminder. I have built a simple app to do that using java.util.Timer, but my problem is that I would automatically like the window to close after 1 minute if the user doesn't close it. For example if I am away from my pc for a few hours I don't want to come back and find lots of reminder windows on top of each other.
Any ideas?
Maybe I should have a single frame that automatically minimises and maximises itself instead?
Rob Ross

Joined: Jan 07, 2002
Posts: 2205
You can use a Timer for that as well. Start a timer when the window is set to visible. You can re-set the timer as needed whenever some activity occurs in the the window, perhaps by overriding repaint() to start a new Timer, then call the superclass version.
If the timer counts down to zero, have it invoke a method in your Frame that closes it, ie, calls dispose(), or setVisible(false), etc.

SCJP 1.4
Jo Cook

Joined: Mar 20, 2002
Posts: 2
duh! of course it's dispose...
Thanks Rob - can't see the wood for the trees

I agree. Here's the link:
subject: Automatically closing windows after time
It's not a secret anymore!