List of usage examples for java.awt.event WindowEvent WINDOW_CLOSING
int WINDOW_CLOSING
To view the source code for java.awt.event WindowEvent WINDOW_CLOSING.
Click Source Link
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 www. j a v a 2 s . c om*/ * * @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)); }/*from www . jav a 2 s .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
/** * Attaches a key event listener to given component, disposing of the given window * upon pressing escape within the context. * /* w ww. j a v a 2 s .c o m*/ * @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) { if (e.getID() == WindowEvent.WINDOW_CLOSING) { System.out.println(WindowEvent.WINDOW_CLOSING); dispose();/*from www .j av a2 s. c om*/ System.exit(0); } 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.c om*/ }; 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 a va 2s . co 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// w w w .j a va2s . co 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:com.babynamesUI.java
protected void processWindowEvent(WindowEvent e) { if (e.getID() == WindowEvent.WINDOW_CLOSING) { //System.exit(0); //remove on release int exit = JOptionPane.showConfirmDialog(this, "Are you sure?", "Confirm Exit?", JOptionPane.YES_NO_OPTION); if (exit == JOptionPane.YES_OPTION) { System.exit(0);/*from w ww . j a v a 2 s . c o m*/ } } else { super.processWindowEvent(e); } }