java.awt.event.WindowListener源码实例Demo

类java.awt.event.WindowListener源码实例Demo

下面列出了java.awt.event.WindowListener 类实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: jdk1.8-source-analysis   文件: JOptionPane.java
private JDialog createDialog(Component parentComponent, String title,
        int style)
        throws HeadlessException {

    final JDialog dialog;

    Window window = JOptionPane.getWindowForComponent(parentComponent);
    if (window instanceof Frame) {
        dialog = new JDialog((Frame)window, title, true);
    } else {
        dialog = new JDialog((Dialog)window, title, true);
    }
    if (window instanceof SwingUtilities.SharedOwnerFrame) {
        WindowListener ownerShutdownListener =
                SwingUtilities.getSharedOwnerFrameShutdownListener();
        dialog.addWindowListener(ownerShutdownListener);
    }
    initDialog(dialog, style, parentComponent);
    return dialog;
}
 
源代码2 项目: dragonwell8_jdk   文件: JOptionPane.java
private JDialog createDialog(Component parentComponent, String title,
        int style)
        throws HeadlessException {

    final JDialog dialog;

    Window window = JOptionPane.getWindowForComponent(parentComponent);
    if (window instanceof Frame) {
        dialog = new JDialog((Frame)window, title, true);
    } else {
        dialog = new JDialog((Dialog)window, title, true);
    }
    if (window instanceof SwingUtilities.SharedOwnerFrame) {
        WindowListener ownerShutdownListener =
                SwingUtilities.getSharedOwnerFrameShutdownListener();
        dialog.addWindowListener(ownerShutdownListener);
    }
    initDialog(dialog, style, parentComponent);
    return dialog;
}
 
源代码3 项目: TencentKona-8   文件: JOptionPane.java
private JDialog createDialog(Component parentComponent, String title,
        int style)
        throws HeadlessException {

    final JDialog dialog;

    Window window = JOptionPane.getWindowForComponent(parentComponent);
    if (window instanceof Frame) {
        dialog = new JDialog((Frame)window, title, true);
    } else {
        dialog = new JDialog((Dialog)window, title, true);
    }
    if (window instanceof SwingUtilities.SharedOwnerFrame) {
        WindowListener ownerShutdownListener =
                SwingUtilities.getSharedOwnerFrameShutdownListener();
        dialog.addWindowListener(ownerShutdownListener);
    }
    initDialog(dialog, style, parentComponent);
    return dialog;
}
 
源代码4 项目: jdk8u60   文件: JOptionPane.java
private JDialog createDialog(Component parentComponent, String title,
        int style)
        throws HeadlessException {

    final JDialog dialog;

    Window window = JOptionPane.getWindowForComponent(parentComponent);
    if (window instanceof Frame) {
        dialog = new JDialog((Frame)window, title, true);
    } else {
        dialog = new JDialog((Dialog)window, title, true);
    }
    if (window instanceof SwingUtilities.SharedOwnerFrame) {
        WindowListener ownerShutdownListener =
                SwingUtilities.getSharedOwnerFrameShutdownListener();
        dialog.addWindowListener(ownerShutdownListener);
    }
    initDialog(dialog, style, parentComponent);
    return dialog;
}
 
源代码5 项目: JDKSourceCode1.8   文件: JOptionPane.java
private JDialog createDialog(Component parentComponent, String title,
        int style)
        throws HeadlessException {

    final JDialog dialog;

    Window window = JOptionPane.getWindowForComponent(parentComponent);
    if (window instanceof Frame) {
        dialog = new JDialog((Frame)window, title, true);
    } else {
        dialog = new JDialog((Dialog)window, title, true);
    }
    if (window instanceof SwingUtilities.SharedOwnerFrame) {
        WindowListener ownerShutdownListener =
                SwingUtilities.getSharedOwnerFrameShutdownListener();
        dialog.addWindowListener(ownerShutdownListener);
    }
    initDialog(dialog, style, parentComponent);
    return dialog;
}
 
源代码6 项目: openjdk-jdk8u   文件: JOptionPane.java
private JDialog createDialog(Component parentComponent, String title,
        int style)
        throws HeadlessException {

    final JDialog dialog;

    Window window = JOptionPane.getWindowForComponent(parentComponent);
    if (window instanceof Frame) {
        dialog = new JDialog((Frame)window, title, true);
    } else {
        dialog = new JDialog((Dialog)window, title, true);
    }
    if (window instanceof SwingUtilities.SharedOwnerFrame) {
        WindowListener ownerShutdownListener =
                SwingUtilities.getSharedOwnerFrameShutdownListener();
        dialog.addWindowListener(ownerShutdownListener);
    }
    initDialog(dialog, style, parentComponent);
    return dialog;
}
 
源代码7 项目: netbeans   文件: RevisionPicker.java
public boolean open () {
    dd = new DialogDescriptor(panel, NbBundle.getMessage(RevisionPicker.class, "LBL_RevisionPickerDialog.title"), //NOI18N
            true, new Object[] { okButton, DialogDescriptor.CANCEL_OPTION }, okButton, DialogDescriptor.DEFAULT_ALIGN, new HelpCtx("org.netbeans.modules.git.ui.repository.RevisionPickerDialog"), null); //NOI18N
    Dialog dialog = DialogDisplayer.getDefault().createDialog(dd);
    updateDialogState();
    browserPanel.addPropertyChangeListener(this);
    Preferences prefs = GitModuleConfig.getDefault().getPreferences();
    WindowListener windowListener = new DialogBoundsPreserver(prefs, this.getClass().getName());
    dialog.addWindowListener(windowListener);
    windowListener.windowOpened(new WindowEvent(dialog, WindowEvent.WINDOW_OPENED));
    dialog.pack();
    updateSliders(prefs);
    dialog.setVisible(true);
    persistSliders(prefs);
    browserPanel.removePropertyChangeListener(this);
    return dd.getValue() == okButton;
}
 
源代码8 项目: openjdk-jdk8u-backup   文件: JOptionPane.java
private JDialog createDialog(Component parentComponent, String title,
        int style)
        throws HeadlessException {

    final JDialog dialog;

    Window window = JOptionPane.getWindowForComponent(parentComponent);
    if (window instanceof Frame) {
        dialog = new JDialog((Frame)window, title, true);
    } else {
        dialog = new JDialog((Dialog)window, title, true);
    }
    if (window instanceof SwingUtilities.SharedOwnerFrame) {
        WindowListener ownerShutdownListener =
                SwingUtilities.getSharedOwnerFrameShutdownListener();
        dialog.addWindowListener(ownerShutdownListener);
    }
    initDialog(dialog, style, parentComponent);
    return dialog;
}
 
源代码9 项目: Bytecoder   文件: JOptionPane.java
private JDialog createDialog(Component parentComponent, String title,
        int style)
        throws HeadlessException {

    final JDialog dialog;

    Window window = JOptionPane.getWindowForComponent(parentComponent);
    if (window instanceof Frame) {
        dialog = new JDialog((Frame)window, title, true);
    } else {
        dialog = new JDialog((Dialog)window, title, true);
    }
    if (window instanceof SwingUtilities.SharedOwnerFrame) {
        WindowListener ownerShutdownListener =
                SwingUtilities.getSharedOwnerFrameShutdownListener();
        dialog.addWindowListener(ownerShutdownListener);
    }
    initDialog(dialog, style, parentComponent);
    return dialog;
}
 
源代码10 项目: openjdk-jdk9   文件: JOptionPane.java
private JDialog createDialog(Component parentComponent, String title,
        int style)
        throws HeadlessException {

    final JDialog dialog;

    Window window = JOptionPane.getWindowForComponent(parentComponent);
    if (window instanceof Frame) {
        dialog = new JDialog((Frame)window, title, true);
    } else {
        dialog = new JDialog((Dialog)window, title, true);
    }
    if (window instanceof SwingUtilities.SharedOwnerFrame) {
        WindowListener ownerShutdownListener =
                SwingUtilities.getSharedOwnerFrameShutdownListener();
        dialog.addWindowListener(ownerShutdownListener);
    }
    initDialog(dialog, style, parentComponent);
    return dialog;
}
 
源代码11 项目: jdk8u-jdk   文件: JOptionPane.java
private JDialog createDialog(Component parentComponent, String title,
        int style)
        throws HeadlessException {

    final JDialog dialog;

    Window window = JOptionPane.getWindowForComponent(parentComponent);
    if (window instanceof Frame) {
        dialog = new JDialog((Frame)window, title, true);
    } else {
        dialog = new JDialog((Dialog)window, title, true);
    }
    if (window instanceof SwingUtilities.SharedOwnerFrame) {
        WindowListener ownerShutdownListener =
                SwingUtilities.getSharedOwnerFrameShutdownListener();
        dialog.addWindowListener(ownerShutdownListener);
    }
    initDialog(dialog, style, parentComponent);
    return dialog;
}
 
源代码12 项目: Java8CN   文件: JOptionPane.java
private JDialog createDialog(Component parentComponent, String title,
        int style)
        throws HeadlessException {

    final JDialog dialog;

    Window window = JOptionPane.getWindowForComponent(parentComponent);
    if (window instanceof Frame) {
        dialog = new JDialog((Frame)window, title, true);
    } else {
        dialog = new JDialog((Dialog)window, title, true);
    }
    if (window instanceof SwingUtilities.SharedOwnerFrame) {
        WindowListener ownerShutdownListener =
                SwingUtilities.getSharedOwnerFrameShutdownListener();
        dialog.addWindowListener(ownerShutdownListener);
    }
    initDialog(dialog, style, parentComponent);
    return dialog;
}
 
源代码13 项目: hottub   文件: JOptionPane.java
private JDialog createDialog(Component parentComponent, String title,
        int style)
        throws HeadlessException {

    final JDialog dialog;

    Window window = JOptionPane.getWindowForComponent(parentComponent);
    if (window instanceof Frame) {
        dialog = new JDialog((Frame)window, title, true);
    } else {
        dialog = new JDialog((Dialog)window, title, true);
    }
    if (window instanceof SwingUtilities.SharedOwnerFrame) {
        WindowListener ownerShutdownListener =
                SwingUtilities.getSharedOwnerFrameShutdownListener();
        dialog.addWindowListener(ownerShutdownListener);
    }
    initDialog(dialog, style, parentComponent);
    return dialog;
}
 
源代码14 项目: openjdk-8-source   文件: JOptionPane.java
private JDialog createDialog(Component parentComponent, String title,
        int style)
        throws HeadlessException {

    final JDialog dialog;

    Window window = JOptionPane.getWindowForComponent(parentComponent);
    if (window instanceof Frame) {
        dialog = new JDialog((Frame)window, title, true);
    } else {
        dialog = new JDialog((Dialog)window, title, true);
    }
    if (window instanceof SwingUtilities.SharedOwnerFrame) {
        WindowListener ownerShutdownListener =
                SwingUtilities.getSharedOwnerFrameShutdownListener();
        dialog.addWindowListener(ownerShutdownListener);
    }
    initDialog(dialog, style, parentComponent);
    return dialog;
}
 
源代码15 项目: openjdk-8   文件: JOptionPane.java
private JDialog createDialog(Component parentComponent, String title,
        int style)
        throws HeadlessException {

    final JDialog dialog;

    Window window = JOptionPane.getWindowForComponent(parentComponent);
    if (window instanceof Frame) {
        dialog = new JDialog((Frame)window, title, true);
    } else {
        dialog = new JDialog((Dialog)window, title, true);
    }
    if (window instanceof SwingUtilities.SharedOwnerFrame) {
        WindowListener ownerShutdownListener =
                SwingUtilities.getSharedOwnerFrameShutdownListener();
        dialog.addWindowListener(ownerShutdownListener);
    }
    initDialog(dialog, style, parentComponent);
    return dialog;
}
 
源代码16 项目: jdk8u_jdk   文件: JOptionPane.java
private JDialog createDialog(Component parentComponent, String title,
        int style)
        throws HeadlessException {

    final JDialog dialog;

    Window window = JOptionPane.getWindowForComponent(parentComponent);
    if (window instanceof Frame) {
        dialog = new JDialog((Frame)window, title, true);
    } else {
        dialog = new JDialog((Dialog)window, title, true);
    }
    if (window instanceof SwingUtilities.SharedOwnerFrame) {
        WindowListener ownerShutdownListener =
                SwingUtilities.getSharedOwnerFrameShutdownListener();
        dialog.addWindowListener(ownerShutdownListener);
    }
    initDialog(dialog, style, parentComponent);
    return dialog;
}
 
源代码17 项目: beautyeye   文件: SwingSet2.java
/**
 * Create a frame for SwingSet2 to reside in if brought up
 * as an application.
 *
 * @param gc the gc
 * @return the j frame
 */
public static JFrame createFrame(GraphicsConfiguration gc) {
	JFrame frame = new JFrame(gc);
	if (numSSs == 0) {
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	} else {
		WindowListener l = new WindowAdapter() {
			public void windowClosing(WindowEvent e) {
				numSSs--;
				swingSets.remove(this);
			}
		};
		frame.addWindowListener(l);
	}
	
	//由Jack Jiang于2012-09-22加上,防止因JToolBar的大小而影响JFrame的prefereSize使得没法再缩小
	frame.setMinimumSize(new Dimension(100,100));
	return frame;
}
 
源代码18 项目: jdk8u-jdk   文件: JOptionPane.java
private JDialog createDialog(Component parentComponent, String title,
        int style)
        throws HeadlessException {

    final JDialog dialog;

    Window window = JOptionPane.getWindowForComponent(parentComponent);
    if (window instanceof Frame) {
        dialog = new JDialog((Frame)window, title, true);
    } else {
        dialog = new JDialog((Dialog)window, title, true);
    }
    if (window instanceof SwingUtilities.SharedOwnerFrame) {
        WindowListener ownerShutdownListener =
                SwingUtilities.getSharedOwnerFrameShutdownListener();
        dialog.addWindowListener(ownerShutdownListener);
    }
    initDialog(dialog, style, parentComponent);
    return dialog;
}
 
源代码19 项目: jdk8u-dev-jdk   文件: JOptionPane.java
private JDialog createDialog(Component parentComponent, String title,
        int style)
        throws HeadlessException {

    final JDialog dialog;

    Window window = JOptionPane.getWindowForComponent(parentComponent);
    if (window instanceof Frame) {
        dialog = new JDialog((Frame)window, title, true);
    } else {
        dialog = new JDialog((Dialog)window, title, true);
    }
    if (window instanceof SwingUtilities.SharedOwnerFrame) {
        WindowListener ownerShutdownListener =
                SwingUtilities.getSharedOwnerFrameShutdownListener();
        dialog.addWindowListener(ownerShutdownListener);
    }
    initDialog(dialog, style, parentComponent);
    return dialog;
}
 
源代码20 项目: hortonmachine   文件: GuiUtilities.java
public static void addClosingListener( JFrame frame, IOnCloseListener onCloseListener ) {
    WindowListener exitListener = new WindowAdapter(){
        @Override
        public void windowClosing( WindowEvent e ) {
            if (!onCloseListener.canCloseWithoutPrompt()) {
                int confirm = JOptionPane.showOptionDialog(frame, "Are you sure you want to exit?", "Exit Confirmation",
                        JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, null);
                if (confirm == JOptionPane.YES_OPTION) {
                    onCloseListener.onClose();
                    System.exit(0);
                }
            } else {
                onCloseListener.onClose();
                System.exit(0);
            }
        }
    };
    frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
    frame.addWindowListener(exitListener);
}
 
源代码21 项目: cloudstack   文件: Client.java
protected static Frame createVncClientMainWindow(BufferedImageCanvas canvas, String title, WindowListener windowListener) {
    // Create AWT windows
    Frame frame = new Frame(title + " - RDP");

    // Use scrolling pane to support screens, which are larger than ours
    scroller = new ScrollPane(ScrollPane.SCROLLBARS_AS_NEEDED);
    scroller.add(canvas);
    scroller.setSize(canvas.getWidth(), canvas.getHeight());

    frame.add(scroller);
    frame.pack();
    frame.setVisible(true);

    frame.addWindowListener(windowListener);

    return frame;
}
 
源代码22 项目: cropplanning   文件: ChartPanel.java
public static void main(String[] argv) {
  JFrame f = new JFrame();
  f.setSize(400, 300);

  int size = 30;

  List<Double> values = new ArrayList<Double>( size );
  List<String> names = new ArrayList<String>( size );

  for ( int i = 0; i < size; i++ ) {
    values.add( i * 1d );
    names.add( "Item " + i );
  }

  f.getContentPane().add(new ChartPanel( values,
                                         names, "A title"));

  WindowListener wndCloser = new WindowAdapter() {
    public void windowClosing(WindowEvent e) {
      System.exit(0);
    }
  };
  f.addWindowListener(wndCloser);
  f.setVisible(true);
}
 
源代码23 项目: osp   文件: Launcher.java
private void exitCurrentApps() {
  final Frame[] prevFrames = Frame.getFrames();
  for(int i = 0, n = prevFrames.length; i<n; i++) {
    if(existingFrames.contains(prevFrames[i])) {
      continue; // don't mess with pre-existing frames such as the applet plugin
    }
    if(!(prevFrames[i] instanceof LauncherFrame)) {
      WindowListener[] listeners = prevFrames[i].getWindowListeners();
      for(int j = 0; j<listeners.length; j++) {
        listeners[j].windowClosing(null);
      }
      if(prevFrames[i].isVisible()) {
        prevFrames[i].dispose();
      }
    }
  }
}
 
源代码24 项目: darklaf   文件: MouseGrabberUtil.java
/**
 * This Method is responsible for removing the old MouseGrabber from the AppContext, to be able to add our own
 * implementation for it that is a bit more generous with closing the popup.
 */
public static void uninstallOldMouseGrabber(final ChangeListener oldMouseGrabber) {
    if (oldMouseGrabber == null) return;
    MenuSelectionManager menuSelectionManager = MenuSelectionManager.defaultManager();
    menuSelectionManager.removeChangeListener(oldMouseGrabber);
    if (oldMouseGrabber instanceof AWTEventListener) {
        Toolkit tk = Toolkit.getDefaultToolkit();
        java.security.AccessController.doPrivileged((PrivilegedAction<Object>) () -> {
            tk.removeAWTEventListener((AWTEventListener) oldMouseGrabber);
            return null;
        });
    }
    MenuElement[] path = menuSelectionManager.getSelectedPath();
    if (path.length != 0 && path[0] != null) {
        Component invoker = path[0].getComponent();
        if (invoker instanceof JPopupMenu) {
            invoker = ((JPopupMenu) invoker).getInvoker();
        }
        Window grabbedWindow = DarkUIUtil.getWindow(invoker);
        if (oldMouseGrabber instanceof WindowListener) {
            grabbedWindow.removeWindowListener((WindowListener) oldMouseGrabber);
        }
        if (oldMouseGrabber instanceof ComponentListener) {
            grabbedWindow.removeComponentListener((ComponentListener) oldMouseGrabber);
        }
    }
}
 
源代码25 项目: darklaf   文件: PreferenceChangeDemo.java
@Override
public WindowListener createWindowListener() {
    return new WindowAdapter() {
        @Override
        public void windowClosing(final WindowEvent e) {
            LafManager.enabledPreferenceChangeReporting(false);
        }
    };
}
 
源代码26 项目: opt4j   文件: DefaultApplicationFrame.java
@Override
public void startup() {
	WindowListener exitListener = new WindowAdapter() {
		@Override
		public void windowClosing(WindowEvent e) {
			Window window = e.getWindow();
			window.setVisible(false);
			window.dispose();
			try {
				Thread.sleep(1000);
			} catch (InterruptedException ignore) {
			} finally {
				System.exit(0);
			}
		}
	};
	addWindowListener(exitListener);

	setIconImage(Icons.getIcon(Icons.OPT4J).getImage());
	setTitle(title);
	setLayout(new BorderLayout());
	JSeparator jSeparator = new JSeparator();

	JPanel toolBarPanel = new JPanel(new BorderLayout());
	toolBarPanel.add(toolBar, BorderLayout.CENTER);
	toolBarPanel.add(jSeparator, BorderLayout.SOUTH);

	add(toolBarPanel, BorderLayout.NORTH);
	add(contentPanel, BorderLayout.CENTER);

	setJMenuBar(menu);

	menu.startup();
	toolBar.startup();
	contentPanel.startup();

	pack();
	setVisible(true);
}
 
源代码27 项目: Bytecoder   文件: Window.java
/**
 * Processes window events occurring on this window by
 * dispatching them to any registered WindowListener objects.
 * NOTE: This method will not be called unless window events
 * are enabled for this component; this happens when one of the
 * following occurs:
 * <ul>
 * <li>A WindowListener object is registered via
 *     {@code addWindowListener}
 * <li>Window events are enabled via {@code enableEvents}
 * </ul>
 * <p>Note that if the event parameter is {@code null}
 * the behavior is unspecified and may result in an
 * exception.
 *
 * @param e the window event
 * @see Component#enableEvents
 */
protected void processWindowEvent(WindowEvent e) {
    WindowListener listener = windowListener;
    if (listener != null) {
        switch(e.getID()) {
            case WindowEvent.WINDOW_OPENED:
                listener.windowOpened(e);
                break;
            case WindowEvent.WINDOW_CLOSING:
                listener.windowClosing(e);
                break;
            case WindowEvent.WINDOW_CLOSED:
                listener.windowClosed(e);
                break;
            case WindowEvent.WINDOW_ICONIFIED:
                listener.windowIconified(e);
                break;
            case WindowEvent.WINDOW_DEICONIFIED:
                listener.windowDeiconified(e);
                break;
            case WindowEvent.WINDOW_ACTIVATED:
                listener.windowActivated(e);
                break;
            case WindowEvent.WINDOW_DEACTIVATED:
                listener.windowDeactivated(e);
                break;
            default:
                break;
        }
    }
}
 
源代码28 项目: openjdk-jdk9   文件: WindowOperator.java
/**
 * Maps {@code Window.addWindowListener(WindowListener)} through queue
 */
public void addWindowListener(final WindowListener windowListener) {
    runMapping(new MapVoidAction("addWindowListener") {
        @Override
        public void map() {
            ((Window) getSource()).addWindowListener(windowListener);
        }
    });
}
 
源代码29 项目: openjdk-jdk9   文件: WindowOperator.java
/**
 * Maps {@code Window.removeWindowListener(WindowListener)} through queue
 */
public void removeWindowListener(final WindowListener windowListener) {
    runMapping(new MapVoidAction("removeWindowListener") {
        @Override
        public void map() {
            ((Window) getSource()).removeWindowListener(windowListener);
        }
    });
}
 
源代码30 项目: swift-k   文件: EventWait.java
private void waitForEvent(LWThread thr, Stack stack) {
	k.rt.Channel<Object> vargs = c_vargs.get(stack);
	
	FutureCounter counter = new FutureCounter(vargs.size()); 
	for (Object arg : vargs) {
		if (!(arg instanceof List)) {
			throw new ExecutionException("Each argument must be a list");
		}
		List<?> list = (List<?>) arg;
		if (list.size() != 3) {
			throw new ExecutionException("Each argument must be a list containing 3 items");
		}
		try {
			String ret = (String) list.get(0);
			String type = (String) list.get(1);
			Object source = list.get(2);
			if ("java.awt.events.ActionEvent".equals(type)) {
				addListener(source, "addActionListener", ActionListener.class, counter);
			}
			else if ("java.awt.events.WindowEvent".equals(type)) {
				addListener(source, "addWindowListener", WindowListener.class, counter);
			}
			else {
				throw new ExecutionException("Unknown event type: " + type);
			}
		}
		catch (Exception e) {
			throw new ExecutionException("Exception caught while adding listener", e);
		}
	}
	throw new ConditionalYield(2, 3, counter);
}