Example usage for java.awt Frame removeWindowListener

List of usage examples for java.awt Frame removeWindowListener

Introduction

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

Prototype

public synchronized void removeWindowListener(WindowListener l) 

Source Link

Document

Removes the specified window listener so that it no longer receives window events from this window.

Usage

From source file:ModalFrameUtil.java

public static void showAsModal(final Frame frame, final Frame owner) {
    frame.addWindowListener(new WindowAdapter() {
        public void windowOpened(WindowEvent e) {
            owner.setEnabled(false);/*from   w w  w  .  ja  v a2s  .  co  m*/
        }

        public void windowClosing(WindowEvent e) {
            owner.setEnabled(true);
            frame.removeWindowListener(this);
        }

        public void windowClosed(WindowEvent e) {
            owner.setEnabled(true);
            frame.removeWindowListener(this);
        }
    });

    owner.addWindowListener(new WindowAdapter() {
        public void windowActivated(WindowEvent e) {
            if (frame.isShowing()) {
                frame.setExtendedState(JFrame.NORMAL);
                frame.toFront();
            } else {
                owner.removeWindowListener(this);
            }
        }
    });

    frame.setVisible(true);
    try {
        new EventPump(frame).start();
    } catch (Throwable throwable) {
        throw new RuntimeException(throwable);
    }
}