• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

ShutDownHandling for Swing Application

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 1365
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Manjunatha N.S.
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic