List of usage examples for java.awt EventQueue postEvent
public void postEvent(AWTEvent theEvent)
From source file:Main.java
private static void dispatchEventsUntilNow() { if (java.awt.EventQueue.isDispatchThread() && !isDispatching) { isDispatching = true;/*from ww w .ja v a 2 s . c om*/ try { int handled = 0; java.awt.EventQueue eventQ = java.awt.Toolkit.getDefaultToolkit().getSystemEventQueue(); class StopEvent extends AWTEvent { StopEvent() { super(new Object(), 0); } } eventQ.postEvent(new StopEvent()); while (true) { try { AWTEvent event = eventQ.getNextEvent(); if (event instanceof StopEvent) { break; } if (event instanceof ActiveEvent) { ((ActiveEvent) event).dispatch(); } else { Object source = event.getSource(); if (source instanceof Component) { Component comp = (Component) source; comp.dispatchEvent(event); } } handled++; } catch (InterruptedException e) { //hmm } } // Debug.trace("####dispatchEventsUntilNow handeld "+(handled)+" events"); } finally { isDispatching = false; } } }