本文整理匯總了Java中java.awt.EventQueue.getNextEvent方法的典型用法代碼示例。如果您正苦於以下問題:Java EventQueue.getNextEvent方法的具體用法?Java EventQueue.getNextEvent怎麽用?Java EventQueue.getNextEvent使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.awt.EventQueue
的用法示例。
在下文中一共展示了EventQueue.getNextEvent方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: dispatchNextGuiEvent
import java.awt.EventQueue; //導入方法依賴的package包/類
/**
* Processes the next GUI event.
*/
public void dispatchNextGuiEvent() throws InterruptedException {
EventQueue queue = awtEventQueue;
if (queue == null) {
queue = Toolkit.getDefaultToolkit().getSystemEventQueue();
awtEventQueue = queue;
}
AWTEvent event = queue.getNextEvent();
if (event instanceof ActiveEvent) {
((ActiveEvent)event).dispatch();
} else {
Object source = event.getSource();
if (source instanceof Component) {
Component comp = (Component)source;
comp.dispatchEvent(event);
} else if (source instanceof MenuComponent) {
((MenuComponent)source).dispatchEvent(event);
}
}
}
示例2: drainEventQueue
import java.awt.EventQueue; //導入方法依賴的package包/類
/** Drain the event queue. ONLY CALL THIS METHOD FROM THE EVENT DISPATCH
* THREAD OR IT WILL DO BAD THINGS! */
private static void drainEventQueue() throws Exception {
AWTEvent evt = EventQueue.getCurrentEvent();
//Dispatch any events that the code that just ran may have generated,
//so dialogs appear, things get focus and paint, stuff like that
while (Toolkit.getDefaultToolkit().getSystemEventQueue().peekEvent() != null) {
//do fetch this every time, its value can change
EventQueue queue = Toolkit.getDefaultToolkit().getSystemEventQueue();
evt = queue.getNextEvent();
dispatchEvent(queue, evt);
}
}
示例3: setVisible
import java.awt.EventQueue; //導入方法依賴的package包/類
@Override
public void setVisible(boolean visible) {
boolean blockParent = (visible && modal);
owner.setEnabled(!blockParent);
owner.setFocusableWindowState(!blockParent);
super.setVisible(visible);
if (blockParent) {
owner.addWindowListener(parentWindowListener);
try {
if (SwingUtilities.isEventDispatchThread()) {
EventQueue theQueue = getToolkit().getSystemEventQueue();
while (isVisible()) {
AWTEvent event = theQueue.getNextEvent();
Object src = event.getSource();
if (event instanceof ActiveEvent) {
((ActiveEvent) event).dispatch();
} else if (src instanceof Component) {
((Component) src).dispatchEvent(event);
}
}
} else {
synchronized (getTreeLock()) {
while (isVisible()) {
try {
getTreeLock().wait();
} catch (InterruptedException e) {
break;
}
}
}
}
}
catch (Exception ex) {
ex.printStackTrace();
}
} else {
owner.removeWindowListener(parentWindowListener);
// added 2 lines
owner.setEnabled(true);
owner.setFocusableWindowState(true);
}
}