File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes WindowAdapter Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "WindowAdapter" Watch "WindowAdapter" New topic


Alex Gregory
Ranch Hand

Joined: Jun 15, 2002
Posts: 46
Hi, I want to display a pop up box to ascertain whether user really wants to exit. I use a JOptionPane and if the answer is yes i do a graceful shutdown. but if the answer is no i have no way of cancelling the request, the window just closes without the application shutting down, since you could see that the prompt is still not showing.
I implement the windowClosing(WindowEvent ev) in WindowAdapter.
Any ideas hopefully?
Mark Spritzler

Joined: Feb 05, 2001
Posts: 17276

Yeah, I have an idea, but you probably won't like it.
Just don't pop up a Dialog when they close the window. Assume that the reason why the user clicked the close window/exit button is because they want to exit the program.
I know in Word if you haven't saved your changes it asks if you want to save, but what are we saving here that really needs saving. (Again this is the assignment, not the real world. )

Have fun

Perfect World Programming, LLC - iOS Apps
How to Ask Questions the Smart Way FAQ
Alex Gregory
Ranch Hand

Joined: Jun 15, 2002
Posts: 46
I like your thinking Mark, you're right. If they managed to click on the small x and place the right location, than it was probably not by chance, so i will assume they wanted to exit. The last thing i need is another complication. thanks for the advice.
Eduard Jodas
Ranch Hand

Joined: May 14, 2002
Posts: 80
Just in case you change your mind:
call frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
Alex Gregory
Ranch Hand

Joined: Jun 15, 2002
Posts: 46
Thanks Eduard, I'll keep that function call in mind for my future applications.
I agree. Here's the link:
subject: WindowAdapter
jQuery in Action, 3rd edition