在
Robot你提到的方法应该 不是
在美国东部时间运行。查看源代码后发现,这些“事件”方法中的每一个都有一个共同点(即
afterEvent调用):
public synchronized void keyPress(int keypre) { checkKeypreArgument(keypre); peer.keyPress(keypre); afterEvent();}public synchronized void mousePress(int buttons) { checkButtonsArgument(buttons); peer.mousePress(buttons); afterEvent();}// etcprivate void afterEvent() { autoWaitForIdle(); autoDelay();}private void autoWaitForIdle() { if (isAutoWaitForIdle) { waitForIdle(); }}public synchronized void waitForIdle() { checkNotDispatchThread(); }private void checkNotDispatchThread() { if (EventQueue.isDispatchThread()) { throw new IllegalThreadStateException("Cannot call method from the event dispatcher thread"); }}如果你调用任何这些方法在EDT而
Robot.isAutoWaitForIdle为
true,一个异常将被抛出。这有理由说明,即使
isAutoWaitForIdle是
false,也不应从EDT调用这些方法。



