aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes ShutDownHandling for Swing Application Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "ShutDownHandling for Swing Application" Watch "ShutDownHandling for Swing Application" New topic
Author

ShutDownHandling for Swing Application

Manjunatha N.S.
Greenhorn

Joined: Dec 30, 2003
Posts: 16
In Swing Application how to handle ShutDown operation for eg. like displaying Dialog box with modified files before existing SwingApplication.

I tried with Runtime.addShutDownHook() it is not possible display the Dialog Box, as AWT Thread is also in Shut Down Process. I Observed in NetBeansIDE my requirement is working fine.

Can any one knows about it or how it is implemented in NetBeans.

thanx in advance
Manju
David Weitzman
Ranch Hand

Joined: Jul 27, 2001
Posts: 1365
Normally a user will close an application by choosing Quit from a menu or trying the close the main window. Here's an example of what it might look like if you want to intercept the window closing if there are open files:

(I haven't tried compiling this code so there may be naming errors)



It's best to give the user a "Yes, No, Cancel" option. Cancel would be implemented by not calling dispose(), which is the method that actually closes the frame.
Manjunatha N.S.
Greenhorn

Joined: Dec 30, 2003
Posts: 16
thanks for answer, what you stated is for Normal Exit of the Application, but some time GUI Components may hang and resulting in whole application hanging and then User want close the application by Windows TaskManager End task or with Kill command on Unix. So this Abnormal Exit, in this case also I want handle clean Exit by asking modifed files to be saved.

hope your clear.

thanks
Manju
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15300
    
    6

Originally posted by Manjunatha N.S.:
thanks for answer, what you stated is for Normal Exit of the Application, but some time GUI Components may hang and resulting in whole application hanging and then User want close the application by Windows TaskManager End task or with Kill command on Unix. So this Abnormal Exit, in this case also I want handle clean Exit by asking modifed files to be saved.

hope your clear.

thanks
Manju


If the application hangs, there is no way to do this. The application is hung. If the application is not responding, well, how is it going to perform any more tasks? It can't.


GenRocket - Experts at Building Test Data
Manjunatha N.S.
Greenhorn

Joined: Dec 30, 2003
Posts: 16
hanging of application leave it, in NetBeans IDE if you try to kill the application from Windows Task Manager, then also Dialog box appears which show you all modified file, this kind of feature I want to implement in my application.

thanks
Manju
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15300
    
    6

Ok, here is what I am thinking.

A. Netbeans I believe uses a bit of JNI for this hook. I am installing Netbeans right now because I can't remember. If this is the case, you will have to look into JNI and some Win32 API to figure out how this is done. So, pretty much out of the scope of this forum.

B. If the application is responding ok why on earth would you kill the system process instead of just closing the app? If you are trying to cover all possiible closing issues and the saving of documents, I wouldn't waste my time. If the user is dumb enough to "End Task" or "kill" the running process when they could have just as easily closed it the proper way, then that's their problem. Not ours as developers to compensate for.

I'll let you know what I figure out after I install Netbeans.
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15300
    
    6

Ok, I installed Netbeans and made a change to a document and didn't save it. I then opened my Task Manager and did and End Task on the runide.exe which is the executable Netbeans uses to launch. Netbeans closed and didn't ask me if I wanted to save any changes.

So I guess I don't know what you are wanting because what you described that Netbeans does, Netbeans doesn't do.
Manjunatha N.S.
Greenhorn

Joined: Dec 30, 2003
Posts: 16
Hi Gregg,

you are very close to reproducing, in Windows Task Manger instead of kill ruinde.exe under Process Tab, try to kill NetBeans in 'Applications Tab'.

Actually I am trying to cover all possible way of avoiding losing of user data becuause i observed this case in NetBeans.



hope you explore more into this, I will be greatful to you.

thanks
Manju
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ShutDownHandling for Swing Application