• 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

WindowsClosing

 
Greenhorn
Posts: 2
Eclipse IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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);
 
reply
    Bookmark Topic Watch Topic
  • New Topic