Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

WindowsClosing  RSS feed

 
Chris Romkema
Greenhorn
Posts: 2
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First post here on Javaranch...don't shoot me for it

I want to add a windowlistener to my JFrame that pops up a dialog. If the 'Yes' option is chosen then the JFrame must close, if the 'No' option is chosen then the JFrame must remain in tact.

So far I have something in the line of this.

(this is located in the constructor of my JFrame)


Can someone please tell me what I must do where the comment is now or give me a hint which other options I have to perform something like this?

Thanks in advance

Chris
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you want to change your thinking slightly.

where you have != YES do something, want you want is if it actually is YES,
then you close. anything other than YES, no action is taken


to make this work correctly, you will also need this line (in the constructor)
this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!