This week's giveaway is in the EJB and other Java EE Technologies forum. We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line! See this thread for details.
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.
Joined: Dec 30, 2003
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.
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.
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.
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.
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.
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.
Joined: Dec 30, 2003
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.