/**
* Causes <code>runnable</code> to have its <code>run</code>
* method called in the dispatch thread of
* {@link Toolkit#getSystemEventQueue the system EventQueue}.
* This will happen after all pending events are processed.
* The call blocks until this has happened. This method
* will throw an Error if called from the event dispatcher thread.
*
* @param runnable the <code>Runnable</code> whose <code>run</code>
* method should be executed
* synchronously on the <code>EventQueue</code>
* @exception InterruptedException if any thread has
* interrupted this thread
* @exception InvocationTargetException if an throwable is thrown
* when running <code>runnable</code>
* @see #invokeLater
* @since 1.2
*/
public static void invokeAndWait(Runnable runnable)
throws InterruptedException, InvocationTargetException {
if (EventQueue.isDispatchThread()) {
throw new Error("Cannot call invokeAndWait from the event dispatcher thread");
}
class AWTInvocationLock {}
Object lock = new AWTInvocationLock();
InvocationEvent event =
new InvocationEvent(Toolkit.getDefaultToolkit(), runnable, lock,
true);
synchronized (lock) {
Toolkit.getEventQueue().postEvent(event);
lock.wait();
}
Throwable eventThrowable = event.getThrowable();
if (eventThrowable != null) {
throw new InvocationTargetException(eventThrowable);
}
}
EventQueue.java 文件源码
java
阅读 31
收藏 0
点赞 0
评论 0
项目:VarJ
作者:
评论列表
文章目录