本文整理汇总了Java中java.awt.event.InvocationEvent.getThrowable方法的典型用法代码示例。如果您正苦于以下问题:Java InvocationEvent.getThrowable方法的具体用法?Java InvocationEvent.getThrowable怎么用?Java InvocationEvent.getThrowable使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.awt.event.InvocationEvent
的用法示例。
在下文中一共展示了InvocationEvent.getThrowable方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: invokeAndWait
import java.awt.event.InvocationEvent; //导入方法依赖的package包/类
/**
* 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);
}
}
示例2: showInputMethodMenuOnRequesterEDT
import java.awt.event.InvocationEvent; //导入方法依赖的package包/类
private void showInputMethodMenuOnRequesterEDT(Component requester)
throws InterruptedException, InvocationTargetException {
if (requester == null){
return;
}
class AWTInvocationLock {}
Object lock = new AWTInvocationLock();
InvocationEvent event =
new InvocationEvent(requester,
new Runnable() {
public void run() {
showInputMethodMenu();
}
},
lock,
true);
AppContext requesterAppContext = SunToolkit.targetToAppContext(requester);
synchronized (lock) {
SunToolkit.postEvent(requesterAppContext, event);
while (!event.isDispatched()) {
lock.wait();
}
}
Throwable eventThrowable = event.getThrowable();
if (eventThrowable != null) {
throw new InvocationTargetException(eventThrowable);
}
}
示例3: invokeAndWait
import java.awt.event.InvocationEvent; //导入方法依赖的package包/类
static void invokeAndWait(Object source, Runnable runnable)
throws InterruptedException, InvocationTargetException {
if (EventQueue.isDispatchThread()) {
// throw new Error("Cannot call invokeAndWait from the event dispatcher thread");
hc.core.util.LogManager.warning("exec Runnable.run in EventQueue.invokeAndWait at DispatchThread.");
runnable.run();
return;
}
class AWTInvocationLock {
}
Object lock = new AWTInvocationLock();
InvocationEvent event = new InvocationEvent(source, runnable, lock,
true);
synchronized (lock) {
Toolkit.getEventQueue().postEvent(event);
while (!event.isDispatched()) {
lock.wait();
}
}
Throwable eventThrowable = event.getThrowable();
if (eventThrowable != null) {
throw new InvocationTargetException(eventThrowable);
}
}