Call a method when application closes
In my Swing chat application I have a logout button which is used to logout the user and it works fine. Now I need to logout the user when I close the Swing application window. I did this in web application when closing browser using JavaScript, but now I need to do this in Swing application. How can I achieve this? Call JFrame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE) Add a WindowListener to the frame. Override the appropriate method of the listener to call your closing method, then set the frame invisible and dispose of it. E.G. import java.awt.*; import java.awt.event.*; import