下面列出了java.awt.event.WindowEvent#getWindow() 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
public void eventDispatched(AWTEvent event) {
if (event instanceof WindowEvent) {
WindowEvent windowEvent = (WindowEvent) event;
switch(windowEvent.getID())
{
case WindowEvent.WINDOW_ACTIVATED:
window = windowEvent.getWindow();
break;
case WindowEvent.WINDOW_DEACTIVATED:
window = null;
break;
default:
break;
}
}
}
@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);
}
public void windowActivated(WindowEvent e) {
logger.entering(getClass().getName(), "windowActivated");
WeakReference<RootPaneContainer> ww = getWeak((RootPaneContainer)e.getWindow());
if (ww != null) {
// place as last item in zOrder list
zOrder.remove(ww);
zOrder.add(ww);
} else {
throw new IllegalArgumentException("Window not attached: " + e.getWindow()); //NOI18N
}
}
/**
* 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);
}
}
@Override
public void windowGainedFocus(WindowEvent event) {
if (event.getWindow() == this) {
WINDOW_LIST.remove(this);
WINDOW_LIST.add(0, this);
}
}
@Override
public void windowClosed(WindowEvent e) {
Window closedWindow = e.getWindow();
Integer freePosition = windowPosition.remove(closedWindow);
closedWindow.removeWindowListener(closeListener);
// Mark as free
if (freePosition != null) {
freeSpaces.add(freePosition);
cleanUp();
}
}
@Override
public void windowClosing(WindowEvent e) {
if (lifecycleManager.getWindow() == e.getWindow()) {
// Primary window closed -> Application shutdown
lifecycleManager.shutdown();
}
else {
// Secondary window closed -> Hide and potentially recycle.
e.getWindow().setVisible(false);
}
}
/**
* Listens for the main window closing, and shuts down the application.
*
* @param event information about the window event.
*/
public void windowClosing(WindowEvent event) {
if (event.getWindow() == this) {
dispose();
System.exit(0);
}
}
/**
* Listens for the main window closing, and shuts down the application.
*
* @param event information about the window event.
*/
public void windowClosing(WindowEvent event) {
if (event.getWindow() == this) {
dispose();
System.exit(0);
}
}
@Override
public void windowClosing(WindowEvent e) {
if ((e != null) && (e.getWindow() != null)) {
saveWindowPosition(e.getWindow());
}
}
public void windowClosing(WindowEvent e) {
Window w = e.getWindow();
w.setVisible(false);
}
@Override
public void windowClosing( final WindowEvent evt )
{
if( evt.getWindow() == this )
dispose();
}