Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

WindowAdapter

 
Alex Gregory
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Mark
 
Alex Gregory
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just in case you change your mind:
call frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
 
Alex Gregory
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Eduard, I'll keep that function call in mind for my future applications.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic