Java WindowEvent WINDOW_STATE_CHANGED

Syntax

WindowEvent.WINDOW_STATE_CHANGED has the following syntax.

public static final int WINDOW_STATE_CHANGED

Example

In the following code shows how to use WindowEvent.WINDOW_STATE_CHANGED field.


/*  ww  w.ja v  a 2 s  . c o  m*/

import java.awt.event.WindowEvent;

import javax.swing.JFrame;

public class Main extends JFrame {
  public Main() {

    setDefaultCloseOperation(EXIT_ON_CLOSE);
    enableEvents(java.awt.AWTEvent.WINDOW_EVENT_MASK);
  }

  protected void processWindowEvent(WindowEvent e) {
    if (e.getID() == WindowEvent.WINDOW_STATE_CHANGED) {
      System.out.println(WindowEvent.WINDOW_STATE_CHANGED);
      dispose();
      System.exit(0);
    }
    super.processWindowEvent(e); // Pass on the event
  }

  public static void main(String[] a) {
    Main window = new Main();
    window.setBounds(30, 30, 300, 300);
    window.setVisible(true);
  }
}




















Home »
  Java Tutorial »
    java.awt.event »




AdjustmentListener
ActionEvent
ActionListener
HierarchyEvent
HierarchyListener
InputEvent
ItemEvent
ItemListener
KeyAdapter
KeyEvent
KeyListener
MouseAdapter
MouseEvent
MouseListener
MouseMotionAdapter
MouseMotionListener
MouseWheelEvent
MouseWheelListener
WindowAdapter
WindowEvent
WindowFocusListener
WindowStateListener