java - How to use something other than the DefaultClosingOperation when closing a JFrame window? -
I am using socket on the chat client, and I want to close the window to execute a certain code. The user clicks the "X" before it (like close the connection properly)
/ << p>
Just extension WindowAdapter , implementation WindowListener .
You will find this concept in all swing listeners. ( MouseListener / MouseAdapter , KeyListener / KeyAdapter , ...) is a listener interface and a adapter class This interface implements with empty methods.
So if you want to respond only to a particular event, then use the adapter and override the desired method.
Example:
setWindowListener (New WindowAdapter () {public void windowClosed (WindowEvent E) {// Cleanup Code}});
Comments
Post a Comment