0

I have a jbutton and when I press it I want that my frame close.

This is my code but it doesn't work

Frame frame=new Frame();
int n = JOptionPane.showConfirmDialog(frame,"Are you sure to exit","Really?",JOptionPane.YES_NO_OPTION);
if(n == JOptionPane.YES_OPTION){
    this.setDefaultCloseOperation(EXIT_ON_CLOSE);
}
dstarh
  • 4,976
  • 5
  • 36
  • 68
Daniele
  • 65
  • 2
  • 12
  • `this.setDefaultCloseOperation(EXIT_ON_CLOSE)` doesn't cause frame *to* close, but describes what strategy should be used *when* frame will be closed. – Pshemo Apr 21 '17 at 13:15
  • [JFrame.setDefaultCloseOperation](https://docs.oracle.com/javase/7/docs/api/javax/swing/JFrame.html#setDefaultCloseOperation(int)) is quite explicite : _Sets the operation that will happen by default when the user initiates a "close" on this frame_ – AxelH Apr 21 '17 at 13:17

0 Answers0