• Post Reply Bookmark Topic Watch Topic
  • New Topic

JFrame close methods?

 
Anton Sotnikov
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello dudes!
I didn't know about right method for correct close operation for JFrame component or kill the object.
I found out few, which of them you are using usually???







 
Darryl Burke
Bartender
Posts: 5155
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are still more ways

If all you want is an unconditional exit, all you need is EXIT_ON_CLOSE.

If you need to validate the state of the application and conditionally veto the closing, you would handle that in a WindowListener#windowClosing(...) along with DO_NOTHING_ON_CLOSE.

For most programs that need to stay alive until a background Thread completes its task, DISPOSE_ON_CLOSE should do the job. I've never run in to sich a situation, so it would be nice if a professional programmer could confirm or deny that.

The only use I can see for HIDE_ON_CLOSE is when the frame may be again displayed in the same run of the program, and such usage is rare. Almost any Swing GUI has just the one JFrame, all other windows being JDialogs, nor often than not obtained from a static JOptionPane method.
 
Darryl Burke
Bartender
Posts: 5155
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also note that HIDE_ON_CLOSE is functionally equivalent to setVisible(false) and EXIT_ON_CLOSE is functionally equivalent to System.exit(0). Read the source (JFrame.java) to understand this better.
 
Campbell Ritchie
Marshal
Posts: 52581
119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Find out about DISPOSE_ON_CLOSE, too.
 
Anton Sotnikov
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which is in the case if jdbc connection broken and application catch exception during execute. Next JFrame get a long pause during that all users bring a big indignations?
What is good way?
 
Campbell Ritchie
Marshal
Posts: 52581
119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A frame does not pause. The thread might, but you must not use the Thread#pause method. You mean what will happen if there is loss of database connectivity and an Exception? Yes, the user will wait impatiently for something to happen. I am not sure there is any way to be absolutely sure the database connection will run without exceptions.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!