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>

"post-text" itemprop = "text">

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

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -