Example usage for java.awt EventQueue peekEvent

List of usage examples for java.awt EventQueue peekEvent

Introduction

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

Prototype

public AWTEvent peekEvent() 

Source Link

Document

Returns the first event on the EventQueue without removing it.

Usage

From source file:Main.java

public Point getClick() {
    EventQueue eq = Toolkit.getDefaultToolkit().getSystemEventQueue();

    while (true) {
        try {/*from  w  ww .j a  v  a  2 s . c  o m*/
            AWTEvent pEvent = eq.peekEvent();

            AWTEvent evt = eq.getNextEvent();
            if (evt.getID() == MouseEvent.MOUSE_PRESSED) {
                MouseEvent mevt = (MouseEvent) evt;
                Point p = mevt.getPoint();
                Point top = getRootPane().getLocation();
                p.x -= top.x;
                p.y -= top.y;
                return p;
            }
        } catch (InterruptedException e) {
        }
    }
}