List of usage examples for java.awt EventQueue getNextEvent
public AWTEvent getNextEvent() throws InterruptedException
From source file:Main.java
private static void dispatchEventsUntilNow() { if (java.awt.EventQueue.isDispatchThread() && !isDispatching) { isDispatching = true;//from w ww .ja v a 2 s .c o m 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; } } }
From source file:Main.java
public Point getClick() { EventQueue eq = Toolkit.getDefaultToolkit().getSystemEventQueue(); while (true) { try {/* w ww .j a v a 2s . c o m*/ 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) { } } }
From source file:Main.java
public Point getClick() { EventQueue eq = Toolkit.getDefaultToolkit().getSystemEventQueue(); System.out.println(eq.isDispatchThread()); while (true) { try {// w w w . j a va2 s. com 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) { } } }
From source file:Main.java
public Point getClick() { EventQueue eq = Toolkit.getDefaultToolkit().getSystemEventQueue(); while (true) { try {//from ww w . ja v a2 s .co 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) { } } }