Example usage for java.awt.event WindowEvent WindowEvent

List of usage examples for java.awt.event WindowEvent WindowEvent

Introduction

In this page you can find the example usage for java.awt.event WindowEvent WindowEvent.

Prototype

public WindowEvent(Window source, int id) 

Source Link

Document

Constructs a WindowEvent object.

Usage

From source file:Main.java

public static void closeWindow(Window window) {
    window.dispatchEvent(new WindowEvent(window, WindowEvent.WINDOW_CLOSING));
}

From source file:Main.java

/**
 * Closes the given {@link JFrame}./*from  w  w w . j a  va  2 s  .c o  m*/
 * 
 * @param win
 *            - the frame to close
 */
public static void kill(JFrame win) {
    if (win == null) {
        return;
    }
    WindowEvent close = new WindowEvent(win, WindowEvent.WINDOW_CLOSING);
    Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(close);
}

From source file:Main.java

public static void installEscapeCloseOperation(final JDialog dialog) {
    Action dispatchClosing = new AbstractAction() {
        public void actionPerformed(ActionEvent event) {
            dialog.dispatchEvent(new WindowEvent(dialog, WindowEvent.WINDOW_CLOSING));
        }/* w  w  w .ja va2  s  .  c o m*/
    };
    JRootPane root = dialog.getRootPane();
    root.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(ESCAPE_KEY_STROKE, ESCAPE_KEY);
    root.getActionMap().put(ESCAPE_KEY, dispatchClosing);
}

From source file:Main.java

/**
 * Attaches a key event listener to given component, disposing of the given window
 * upon pressing escape within the context.
 * //w w w .j a va2s . c  om
 * @param context
 * @param button
 */
public static void simulateExitOnEscape(Component context, JFrame window) {
    context.addKeyListener(new KeyAdapter() {
        @Override
        public void keyPressed(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
                for (WindowListener wl : window.getWindowListeners()) {
                    wl.windowClosing(new WindowEvent(window, WindowEvent.WINDOW_CLOSING));
                }

                if (window != null)
                    window.dispose();
            }
        }
    });
}

From source file:Main.java

protected void processWindowEvent(WindowEvent e) {
    WindowEvent newEvent = new WindowEvent(this, WindowEvent.WINDOW_ACTIVATED);

    super.processWindowEvent(e); // Pass on the event
}

From source file:Main.java

public static void closeWindow(Window w) {
    w.getToolkit().getSystemEventQueue().postEvent(new WindowEvent(w, WindowEvent.WINDOW_CLOSING));
}

From source file:Main.java

public static void installEscapeCloseOperation(final JFrame dialog) {
    Action dispatchClosing = new AbstractAction() {
        public void actionPerformed(ActionEvent event) {
            dialog.dispatchEvent(new WindowEvent(dialog, WindowEvent.WINDOW_CLOSING));
        }/*  ww w  .  ja v  a 2s. co  m*/
    };
    JRootPane root = dialog.getRootPane();
    root.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(ESCAPE_KEY_STROKE, ESCAPE_KEY);
    root.getActionMap().put(ESCAPE_KEY, dispatchClosing);
}

From source file:Main.java

public Main() {
    this.setLayout(new GridLayout(0, 1));
    this.add(new JLabel("Dialog close test.", JLabel.CENTER));
    this.add(new JButton(new AbstractAction("Close") {
        @Override/*from w w  w .j ava 2s .  c  o  m*/
        public void actionPerformed(ActionEvent e) {
            Main.this.setVisible(false);
            Main.this.dispatchEvent(new WindowEvent(Main.this, WindowEvent.WINDOW_CLOSING));
        }
    }));
}

From source file:Main.java

public Main() {
    this.setLayout(new GridLayout(0, 1));
    this.add(new JLabel("Dialog event test.", JLabel.CENTER));
    this.add(new JButton(new AbstractAction("Close") {
        @Override//from w  w  w  .j  a  va  2  s  .c  o m
        public void actionPerformed(ActionEvent e) {
            Main.this.setVisible(false);
            Main.this.dispatchEvent(new WindowEvent(Main.this, WindowEvent.WINDOW_CLOSING));
        }
    }));
    this.addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(WindowEvent e) {
            System.out.println(e.paramString());
        }
    });
}

From source file:org.apache.sling.reqanalyzer.impl.RequestAnalyzerWebConsole.java

void dispose() {
    if (this.frame != null) {
        MainFrame frame = this.frame;
        this.frame = null;
        AWTEvent e = new WindowEvent(frame, WindowEvent.WINDOW_CLOSING);
        Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(e);
    }//  www. j a  v  a  2  s .  com
}