1 | initial version |
To trigger events when a JFrame is closed, you can either register a WindowListener or add a WindowAdapter to your JFrame.
Using WindowListener:
frame.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
// Add your code here
}
});
Using WindowAdapter:
frame.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
// Add your code here
}
});
Both of these methods will give you the ability to handle events when the user closes the JFrame by clicking on the close button.