本文整理汇总了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);
}
}