Java 8 WindowEvent - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 WindowEvent class.

This code example shows how to use the following methods:
    assertThat(AWTEvents.wasWindowOpened(event)).isTrue();
  } 
 
  @Test
  public void should_return_false_if_Window_not_opened() { 
    AWTEvent event = new WindowEvent(source, WINDOW_CLOSING);
    assertThat(AWTEvents.wasWindowOpened(event)).isFalse();
  } 
} 
5
CodeRank
This code example shows how to use the following methods:
    assertThat(AWTEvents.wasWindowClosed(event)).isTrue();
  } 
 
  @Test
  public void should_return_false_if_Window_not_closed() { 
    AWTEvent event = new WindowEvent(source, WINDOW_CLOSING);
    assertThat(AWTEvents.wasWindowClosed(event)).isFalse();
  } 
} 
5
CodeRank
This code example shows how to use the following methods:getID, getWindow
  boolean isDuplicateDispose(AWTEvent event) {
    if (!(event instanceof WindowEvent)) {
      return false; 
    } 
    WindowEvent windowEvent = (WindowEvent) event;
    int eventId = windowEvent.getID();
    if (eventId == WINDOW_CLOSING) {
      return false; 
    } 
    if (eventId == WINDOW_CLOSED) {
      Window w = windowEvent.getWindow();
      if (disposedWindows.containsKey(w)) {
        return true; 
      } 
      disposedWindows.put(w, true);
      // execute(addComponentListenerTask(w, new DisposalMonitor(disposedWindows))); 
      w.addComponentListener(new DisposalMonitor(disposedWindows));
      return false; 
    } 
    disposedWindows.remove(windowEvent.getWindow());

5
CodeRank
This code example shows how to use the following methods:getID
     * 
     * @see #setDefaultCloseOperation 
     */ 
    protected void processWindowEvent(WindowEvent e)
    { 
        super.processWindowEvent(e);
 
        if (e.getID() == WindowEvent.WINDOW_OPENED) pack();
    } 
} 
5
CodeRank
This code example shows how to use the following methods:getID
     * 
     * @param e event. 
     */ 
    protected void processWindowEvent(WindowEvent e)
    { 
        super.processWindowEvent(e);
 
        if (e.getID() == WindowEvent.WINDOW_OPENED) pack();
    } 
 
    /** 
     * Returns username from the field. 
     * 
     * @return username. 
     */ 
    public String getUsername()
    { 
        return tfUsername.getText();
    } 
 
5
CodeRank
This code example shows how to use the following methods:getID
     * 
     * @see #setDefaultCloseOperation 
     */ 
    protected void processWindowEvent(WindowEvent e)
    { 
        super.processWindowEvent(e);
 
        if (e.getID() == WindowEvent.WINDOW_OPENED) pack();
    } 
 
    /** 
     * Returns the list of feeds to add. 
     * 
     * @return feeds to add. 
     */ 
    public List getAddFeeds()
    { 
        return FeedCheckBox.getSelected(lstAddFeeds.getModel());
    } 
 
5
CodeRank
This code example shows how to use the following methods:
            } 
        }); 
    } 
 
    public static void closeWindow(Window w) {
        w.getToolkit().getSystemEventQueue().postEvent(new WindowEvent(w, WindowEvent.WINDOW_CLOSING));
    } 
 
    public static Frame getFrame(Component c) {
        Component ret = c;
        while (ret != null && !(ret instanceof Frame)) {
            ret = ret.getParent();
        } 
        return (Frame) ret;
    } 
 
    public static JFrame getJFrame(Component c) {
        Component ret = c;
        while (ret != null && !(ret instanceof JFrame)) {
            ret = ret.getParent();
5
CodeRank
This code example shows how to use the following methods:getWindow
     * Listens for the main window closing, and shuts down the application. 
     * 
     * @param event  information about the window event. 
     */ 
    public void windowClosing(final WindowEvent event) {
        if (event.getWindow() == this) {
            dispose();
            System.exit(0);
        } 
    } 
 
    /** 
     * Required for WindowListener interface, but not used by this class. 
     * 
     * @param event  information about the window event. 
     */ 
    public void windowClosed(final WindowEvent event) {
        // ignore 
    } 
 
5
CodeRank
This code example shows how to use the following methods:getWindow
   * @param y 		initial y coord for the dialog 
   */ 
  protected void initialize(PropertyEditor pe, int x, int y) {
    addWindowListener(new WindowAdapter() {
      public void windowClosing(WindowEvent e) {
	e.getWindow().dispose();
      } 
    }); 
    getContentPane().setLayout(new BorderLayout());
 
    m_Editor = pe;
    m_EditorComponent = pe.getCustomEditor();
    getContentPane().add(m_EditorComponent, BorderLayout.CENTER);
 
    pack();
     
    int screenWidth = getGraphicsConfiguration().getBounds().width;
    int screenHeight = getGraphicsConfiguration().getBounds().height;
 
    // adjust height to a maximum of 95% of screen height 
5
CodeRank
This code example shows how to use the following methods:getWindow
        if (!headless.equalsIgnoreCase("true") && TestData.isInteractiveTest()) {
            try { 
                JFrame frame = new JFrame(getName());
                frame.addWindowListener(new WindowAdapter() {
                    public void windowClosing(WindowEvent e) {
                        e.getWindow().dispose();
                    } 
                }); 
                frame.setContentPane(panel);
                frame.setSize(new Dimension(500,500));
                frame.setVisible(true);
 
                Thread.sleep(5000);
                frame.dispose();
            } catch (HeadlessException exception) {
                // The test is running on a machine without X11 display. Ignore. 
                return; 
            } 
        } 
    } 
5
CodeRank
This code example shows how to use the following methods:getWindow
     * 
     * @param event  information about the window event. 
     */ 
    @Override 
    public void windowClosing(WindowEvent event) {
        if (event.getWindow() == this) {
            dispose();
            System.exit(0);
        } 
    } 
 
    /** 
     * Required for WindowListener interface, but not used by this class. 
     * 
     * @param event  information about the window event. 
     */ 
    @Override 
    public void windowClosed(WindowEvent event) {
        // ignore 
    } 
5
CodeRank
This code example shows how to use the following methods:getWindow
  } 
 
  @RunsInEDT 
  @Override 
  public void windowClosed(WindowEvent e) {
    Window w = e.getWindow();
    w.removeComponentListener(this);
    w.removeWindowListener(this);
  } 
 
  @Override 
  public void componentMoved(ComponentEvent e) {}
 
  @Override 
  public void componentResized(ComponentEvent e) {}
} 
5
CodeRank
This code example shows how to use the following methods:getWindow
    /** 
     * Invoked when a window has been opened. 
     */ 
    public void windowOpened(final WindowEvent e)
    { 
      e.getWindow().toFront();
    } 
  } 
 
  /** 
   * A label that carries the global message that describes the current task. 
   */ 
  private JLabel messageCarrier;
 
  /** 
   * A label containing the report processing pass count. 
   */ 
  private JLabel passCountMessage;
 
  /** 
4
CodeRank
This code example shows how to use the following methods:getSource
    public CloseListener(String key) {
      this.key = key;
    } 
 
    public void windowClosing(WindowEvent e) {
      Window source = (Window) e.getSource();
      saveWindowBounds(key, source);
      source.removeWindowListener(this);
      closeTable.remove(source);
    } 
 
  } 
 
 
  // ------------------------------------------------------------------- 
  // Shutdown handler 
  // ------------------------------------------------------------------- 
 
  private static class ShutdownHandler extends Thread {
 
3
CodeRank
This code example shows how to use the following methods:getWindow
 
    // When a view is selected, find the other views for that document and 
    // bring their frames to the front. 
    private class MultiWindowListener extends WindowAdapter {
        public void windowActivated(WindowEvent e) {
	    Window window = e.getWindow();
            View view = getView(window);
            // FIXME: for some reason, closing 
            //        a view also causes that view 
            //        to be selected after it is 
            //        closed? 
            if(viewList().contains(view)) { 
                // Prevent recursion 
                if (getCurrentView() != view) { 
                    setCurrentView(view); 
                } 
            } 
        } 
 
        public void windowClosing(WindowEvent e) {
4
CodeRank
This code example shows how to use the following methods:getWindow
	@Deprecated 
	public static WindowFocusListener createAndInstallRepaintWindowFocusListener(
			Window window) {
		WindowFocusListener windowFocusListener = new WindowFocusListener() {
			public void windowGainedFocus(WindowEvent e) {
				e.getWindow().repaint();
			} 
 
			public void windowLostFocus(WindowEvent e) {
				e.getWindow().repaint();
			} 
		}; 
		window.addWindowFocusListener(windowFocusListener);
		return windowFocusListener;
	} 
 
	/** 
	 * {@code true} if the given {@link java.awt.Component}'s has a parent {@link java.awt.Window} 
	 * (i.e. it's not null) and that {@link java.awt.Window} is currently active 
	 * (focused). 
4
CodeRank
This code example shows how to use the following methods:getSource
        public void windowActivated(WindowEvent e) {
        } 
        public void windowClosed(WindowEvent e) {
        } 
        public void windowClosing(WindowEvent e) {
            if (e.getSource() == CALIDESplashScreen.this) {
                connEtoC1(); 
            } 
        } 
        public void windowDeactivated(WindowEvent e) {
        } 
        public void windowDeiconified(WindowEvent e) {
        } 
        public void windowIconified(WindowEvent e) {
        } 
        public void windowOpened(WindowEvent e) {
        } 
    } 
     
    private final IvjEventHandler ivjEventHandler = new IvjEventHandler();
3
CodeRank
This code example shows how to use the following methods:getWindow
     *            event is sent to the {@code Window} 
     */ 
    public static WindowListener getClosingWindowAdapter() {
        return new WindowAdapter () {
            public void windowClosing(WindowEvent e) {
                e.getWindow().dispose();
            } 
        }; 
    } 
 
    /* 
     * The values directly map to the ones of 
     * sun.awt.X11.XWM & sun.awt.motif.MToolkit classes. 
     */ 
    public final static int 
        UNDETERMINED_WM = 1,
        NO_WM = 2,
        OTHER_WM = 3,
        OPENLOOK_WM = 4,
        MOTIF_WM = 5,
4
CodeRank
This code example shows how to use the following methods:
 
    /** 
     * Closes the dialog 
     */ 
    private void closeDialog() { 
        dispatchEvent(new WindowEvent(this, WindowEvent.WINDOW_CLOSING));
    } 
 
    private void initComponents() { 
        datePanel = new DatePanel();
        numberCombo = new TransactionNumberComboBox(account);
 
        okButton = new JButton(rb.getString("Button.Ok"));
        cancelButton = new JButton(rb.getString("Button.Cancel"));
 
        okButton.addActionListener(this);
        cancelButton.addActionListener(this);
 
        getRootPane().setDefaultButton(okButton);
    } 
4
CodeRank
This code example shows how to use the following methods:getWindow
	class CleanupWindowChangeListener 
		implements WindowListener
	{ 
		public void windowOpened(WindowEvent e)
		{ 
			if(logger.isDebugEnabled()) logger.debug("windowOpened: {}", e.getWindow());
		} 
 
		public void windowClosing(WindowEvent e)
		{ 
			if(logger.isDebugEnabled()) logger.debug("windowClosing: {}", e.getWindow());
		} 
 
		public void windowClosed(WindowEvent e)
		{ 
			if(logger.isDebugEnabled()) logger.debug("windowClosed: {}", e.getWindow());
			viewContainer.cancelSearching();
			getContentPane().removeAll();
			viewActions.setViewContainer(null); // to remove listener from container
			mainFrame.updateWindowMenus();
4
CodeRank
This code example shows how to use the following methods:getSource
    @Override 
    public void windowClosing(WindowEvent e) {
        if (quitApplicationYesOrNo()) { 
        	try { 
        		//TODO signal shutdown to core... 
                JFrame frame = (JFrame)e.getSource();                
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);        		
        	} catch (Exception exception) {
        		 
        		System.exit(0);
        	} 
        } 
 
    } 
  
} 
3
CodeRank
This code example shows how to use the following methods:getSource
   private void showMatrix(Matrix m, String title){
      ScaleableMatrixPanel smp = new ScaleableMatrixPanel();
      JFrame frame = new JFrame(title);
      frame.addWindowListener(new WindowAdapter(){
         public void windowClosing(WindowEvent e){
            JFrame f = (JFrame) e.getSource();
            f.setVisible(false);
            f.dispose();
         } 
 
 
 
      }); 
 
      smp.setMatrix(m);
 
      frame.getContentPane().add(smp);
 
      frame.pack();
      frame.setVisible(true);
4
CodeRank
This code example shows how to use the following methods:getSource
 
    public void windowOpened(WindowEvent e) {
    } 
 
    public void windowClosing(WindowEvent e) {
        if(e.getSource() == this) dispose();
    } 
 
 
    public void windowClosed(WindowEvent e) {
    } 
 
    /** 
     * Invoked when a window is iconified. 
     */ 
    public void windowIconified(WindowEvent e) {
    } 
 
    /** 
     * Invoked when a window is de-iconified. 
3
CodeRank
This code example shows how to use the following methods:getSource
		return _instance;
	} 
 
	@Override 
	public void windowOpened(WindowEvent e) {
			_objs.add(e.getSource());
	} 
 
	@Override 
	public void windowClosing(WindowEvent e) {
			_objs.remove(e.getSource());
	} 
 
	@Override 
	public void windowClosed(WindowEvent e) {
			_objs.remove(e.getSource());
	} 
 
	@Override 
	public void windowIconified(WindowEvent e) {
3
CodeRank
This code example shows how to use the following methods:
		{ 
			@Override 
			public void actionPerformed(ActionEvent event)
			{ 
				dialog.dispatchEvent(new WindowEvent(dialog,
					WindowEvent.WINDOW_CLOSING));
			} 
		}; 
		JRootPane root = dialog.getRootPane();
		root.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(escapeStroke,
			dispatchWindowClosingActionMapKey);
		root.getActionMap().put(dispatchWindowClosingActionMapKey,
			dispatchClosing);
	} 
 
	/** 
	 * Adjust the crop rectangle to fit within the image it is cropping. Also  
	 * ensure the area is square. 
	 *  
	 * @param image The image being cropped 
4
CodeRank
This code example shows how to use the following methods:getSource
 
    public void windowOpened(WindowEvent e) {
    } 
 
    public void windowClosing(WindowEvent e) {
        if(e.getSource() == this) dispose();
    } 
 
 
    public void windowClosed(WindowEvent e) {
    } 
 
    /** 
     * Invoked when a window is iconified. 
     */ 
    public void windowIconified(WindowEvent e) {
    } 
 
    /** 
     * Invoked when a window is de-iconified. 
3
CodeRank
This code example shows how to use the following methods:getNewState, getOldState
            } 
        } 
 
        public void windowStateChanged(WindowEvent windowEvent) {
            if (showingPopup) {
                int oldState = windowEvent.getOldState();
                int newState = windowEvent.getNewState();
 
                if (((oldState & Frame.ICONIFIED) == 0) &&
                        ((newState & Frame.ICONIFIED) == Frame.ICONIFIED)) {
                    hidePopup(); 
//                } else if (((oldState & Frame.ICONIFIED) == Frame.ICONIFIED) && 
//                           ((newState & Frame.ICONIFIED) == 0 )) { 
//                    //TODO remember we showed before and show again? I guess not worth the efford, not part of spec. 
                } 
            } 
 
        } 
 
        public void componentResized(ComponentEvent evt) {
4
CodeRank
This code example shows how to use the following methods:getSource
	} 
 
    public void windowOpened(WindowEvent e) {  }
 
    public void windowClosing(WindowEvent e) {
        if(e.getSource() == this) dispose();
    } 
 
 
    public void windowClosed(WindowEvent e) { }
 
    /** 
     * Invoked when a window is iconified. 
     */ 
    public void windowIconified(WindowEvent e) { }
 
    /** 
     * Invoked when a window is de-iconified. 
     */ 
    public void windowDeiconified(WindowEvent e) {
4
CodeRank
This code example shows how to use the following methods:
        return account;
    } 
 
    private void cancelAction() { 
        returnStatus = false;
        dispatchEvent(new WindowEvent(this, WindowEvent.WINDOW_CLOSING));
    } 
 
    private void okAction() { 
        account = list.getSelectedAccount();
        returnStatus = true;
        dispatchEvent(new WindowEvent(this, WindowEvent.WINDOW_CLOSING));
    } 
 
    /** 
     * Invoked when an action occurs. 
     */ 
    @Override 
    public void actionPerformed(final ActionEvent e) {
        if (e.getSource() == okButton) {
4
CodeRank
This code example shows how to use the following methods:
    } 
 
    private void stop() { 
        JFrame jf = TwsListener.getMainWindow();
         
        WindowEvent wev = new WindowEvent(jf, WindowEvent.WINDOW_CLOSING);
        Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(wev);
 
        writeAck("Shutting down"); 
    } 
 
    private void writeAck(String message) {if (! (mChannel == null)) mChannel.writeAck(message);}
    private void writeInfo(String message) {if (! (mChannel == null)) mChannel.writeInfo(message);}
    private void writeNack(String message) {if (! (mChannel == null)) mChannel.writeNack(message);}
 
} 
4
CodeRank
See Code Examples for Java 8 WindowEvent Methods: