q.invokeAndWait (new Runnable () { public void run () { } });
EventQueue.invokeAndWait (new Runnable () { public void run () { } });
  public void waitForIdle ()  {    if (EventQueue.isDispatchThread ())      throw new IllegalThreadStateException ("Robot: waitForIdle called from "					     + "the event dispatch thread");    EventQueue q = Toolkit.getDefaultToolkit ().getSystemEventQueue ();	try	  {	q.invokeAndWait (new Runnable () { public void run () { } });	  }	catch (InterruptedException e)  {	    System.err.println ("Robot: waitForIdle interrupted");	  }    catch (InvocationTargetException e)      {	System.err.println ("Robot: waitForIdle cannot invoke target");      }  }