Example usage for java.awt EventQueue postEvent

List of usage examples for java.awt EventQueue postEvent

Introduction

In this page you can find the example usage for java.awt EventQueue postEvent.

Prototype

public void postEvent(AWTEvent theEvent) 

Source Link

Document

Posts a 1.1-style event to the EventQueue .

Usage

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;
        }
    }
}