Example usage for java.awt Frame addWindowStateListener

List of usage examples for java.awt Frame addWindowStateListener

Introduction

In this page you can find the example usage for java.awt Frame addWindowStateListener.

Prototype

public synchronized void addWindowStateListener(WindowStateListener l) 

Source Link

Document

Adds the specified window state listener to receive window events from this window.

Usage

From source file:Main.java

public static void main() {

    Frame frame = new Frame();

    WindowStateListener listener = new WindowAdapter() {
        public void windowStateChanged(WindowEvent evt) {
            int oldState = evt.getOldState();
            int newState = evt.getNewState();

            if ((oldState & Frame.ICONIFIED) == 0 && (newState & Frame.ICONIFIED) != 0) {
                System.out.println("Frame was iconized");
            } else if ((oldState & Frame.ICONIFIED) != 0 && (newState & Frame.ICONIFIED) == 0) {
                System.out.println("Frame was deiconized");
            }/*from w  ww  . j a  v a2 s . c  o  m*/

            if ((oldState & Frame.MAXIMIZED_BOTH) == 0 && (newState & Frame.MAXIMIZED_BOTH) != 0) {
                System.out.println("Frame was maximized");
            } else if ((oldState & Frame.MAXIMIZED_BOTH) != 0 && (newState & Frame.MAXIMIZED_BOTH) == 0) {
                System.out.println("Frame was minimized");
            }
        }
    };

    frame.addWindowStateListener(listener);
    frame.setVisible(true);
}