public synchronized T getResponse() {
        // Wait the thread until 'response' is available. Notice that
        // we have to process the events manually if the current
        // thread is the Event Dispatch Thread (EDT).

        try {
            if (SwingUtilities.isEventDispatchThread()) {
                EventQueue theQueue = getToolkit().getSystemEventQueue();

                while (!responseGiven) {
                    // This is essentially the body of EventDispatchThread
                    AWTEvent event = theQueue.getNextEvent();
                    Object src = event.getSource();

                    try {
                        // We cannot call theQueue.dispatchEvent, so I
                        // pasted its body here:
                        if (event instanceof ActiveEvent) {
                            ((ActiveEvent) event).dispatch();
                        } else if (src instanceof Component) {
                            ((Component) src).dispatchEvent(event);
                        } else if (src instanceof MenuComponent) {
                            ((MenuComponent) src).dispatchEvent(event);
                        } else {
                            logger.warning("unable to dispatch event: "
                                + event);
                        }
                    } finally {
                        continue;
                    }
                }
            } else {
                while (!responseGiven) {
                    wait();
                }
            }
        } catch (InterruptedException e) {}

        T tempResponse = response;
        response = null;
        responseGiven = false;

        return tempResponse;
    }