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);
}