I have set up a JFrame like this:
public class XFrame extends JFrame {
public XFrame() {
setSize(100, 100);
}
@Override
public void dispose() {
super.dispose();
System.out.println("Dispose get called");
}
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
XFrame f = new XFrame();
f.setTitle("Hello World");
//f.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
f.setDefaultCloseOperation(EXIT_ON_CLOSE);
f.setVisible(true);
}
});
}
}
What I expect is that when I press the close button [X] then the dispose method will be called. However, it's the situation only when DISPOSE_ON_CLOSE is set as the DefaultCloseOperation (???). Java really surprises me here. How to implement a method that would be called in both case of DefaultCloseOperation value (DISPOSE_ON_CLOSE & EXIT_ON_CLOSE)?