1

How do you add a ActionListener to the close button (not a JButton the button on the top-right)?

Reaz Murshed
  • 23,691
  • 13
  • 78
  • 98
jjtraversy
  • 11
  • 5

1 Answers1

4

See Closing an Application for a discussion on this topic and a couple of solutions.

Basically you need to do two things:

  1. Use the setDefaultCloseOperation(...) of the frame.
  2. Add a WindowListener to the frame
camickr
  • 321,443
  • 19
  • 166
  • 288