Problem with setDefaultCloseOperation
Hello, after read a few post about this problem neither of them can help me to solve my problem. I hope that you can help me. My problem is the following:
I've installed java1_5_11 and eclipse with Visual editor.
When I tried control the " X" button of the window, launching a jOptionPane asking to the user If he want exit to the application. If I clicked on anyone of options (yes or no) the application is closed.
I run the .java with java bean.
My example is the following:
package pfc.visualinterface;
import java.awt.BorderLayout;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JFrame;
import javax.swing.WindowConstants;
public class cawen extends JFrame {
private static final long serialVersionUID = 1L;
private JPanel jContentPane = null;
/**
* This is the default constructor
*/
public cawen() {
super();
initialize();
}
/**
* This method initializes this
*
* @return void
*/
private void initialize() {
this.setSize(300, 200);
this.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
this.setContentPane(getJContentPane());
this.setTitle("JFrame");
this.setVisible(true);
this.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
int opcion = JOptionPane.showConfirmDialog(cawen.this,"Do you really want to exit?", null, JOptionPane.YES_NO_OPTION);
if (opcion == JOptionPane.YES_OPTION){
System.exit(0);
}
}
});
}
/**
* This method initializes jContentPane
*
* @return javax.swing.JPanel
*/
private JPanel getJContentPane() {
if (jContentPane == null) {
jContentPane = new JPanel();
jContentPane.setLayout(new BorderLayout());
}
return jContentPane;
}
public static void main(String[] args) {
new cawen().setVisible(true);
}
}
Sorry but I don't speak english very well. Thanks in advance

