Listens for window iconify and deiconify events, so that it can stop the animation when the window isn't visible. : Window Event « Swing Event « Java Tutorial






Listens for window iconify and deiconify events, so that it can stop the animation when the window isn't visible.
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;

import javax.swing.JFrame;

public class UsingWindowListener {
  public static void main(String[] args) {
    JFrame aWindow = new JFrame("This is the Window Title");
    aWindow.setBounds(50, 100, 300, 300);
    aWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    aWindow.addWindowListener(new WindowListener() {
      public void windowIconified(WindowEvent e) {
        System.out.println(e);
      }

      public void windowDeiconified(WindowEvent e) {

      }

      public void windowOpened(WindowEvent e) {
      }

      public void windowClosing(WindowEvent e) {
      }

      public void windowClosed(WindowEvent e) {
      }

      public void windowActivated(WindowEvent e) {
      }

      public void windowDeactivated(WindowEvent e) {
      }

    });

    aWindow.setVisible(true);
  }
}








15.41.Window Event
15.41.1.The event IDs for the WindowEvent class
15.41.2.Making a Window Handle its Own EventsMaking a Window Handle its Own Events
15.41.3.The WindowListener Interface: events reflecting changes in the state of a window
15.41.4.Using WindowListenerUsing WindowListener
15.41.5.Using Adapter ClassesUsing Adapter Classes
15.41.6.Listens for window iconify and deiconify events, so that it can stop the animation when the window isn't visible.Listens for window iconify and deiconify events, so that it can stop the animation when the window isn't visible.
15.41.7.WindowListener, WindowFocusListener, WindowStateListener
15.41.8.extends WindowAdapter
15.41.9.Handle a window closing event
15.41.10.Setting the Initial Focused Component in a Window
15.41.11.int java.awt.event.WindowEvent.WINDOW_OPENED