How to close a Frame by clickin on the top right "x"?
awt, frame, java
Solution
You should use a JFrame and then
JFrame AFrame = new JFrame("Frame with components");
AFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
But if you insist on Frame then add a listener:
AFrame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
Problem
Got a Frame in Java: ``` Frame AFrame = new Frame("Frame with components"); ``` The frame's top right "x" close button is not working by default. How can I set that ?