Java Code Examples for java.awt.EventQueue#getNextEvent()
The following examples show how to use
java.awt.EventQueue#getNextEvent() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: XDMFrame.java From xdm with GNU General Public License v2.0 | 6 votes |
private synchronized void startModal(Component comp) { try { if (SwingUtilities.isEventDispatchThread()) { EventQueue theQueue = Toolkit.getDefaultToolkit().getSystemEventQueue(); while (comp.isVisible()) { AWTEvent event = theQueue.getNextEvent(); Object source = event.getSource(); if (event instanceof ActiveEvent) { ((ActiveEvent) event).dispatch(); } else if (source instanceof Component) { ((Component) source).dispatchEvent(event); } else if (source instanceof MenuComponent) { ((MenuComponent) source).dispatchEvent(event); } else { System.err.println("Unable to dispatch: " + event); } } } else { while (comp.isVisible()) { wait(); } } } catch (InterruptedException ignored) { } }
Example 2
Source File: SwingGui.java From JsDroidCmd with Mozilla Public License 2.0 | 6 votes |
/** * Processes the next GUI event. */ public void dispatchNextGuiEvent() throws InterruptedException { EventQueue queue = awtEventQueue; if (queue == null) { queue = Toolkit.getDefaultToolkit().getSystemEventQueue(); awtEventQueue = queue; } AWTEvent event = queue.getNextEvent(); if (event instanceof ActiveEvent) { ((ActiveEvent)event).dispatch(); } else { Object source = event.getSource(); if (source instanceof Component) { Component comp = (Component)source; comp.dispatchEvent(event); } else if (source instanceof MenuComponent) { ((MenuComponent)source).dispatchEvent(event); } } }
Example 3
Source File: SwingGui.java From astor with GNU General Public License v2.0 | 6 votes |
/** * Processes the next GUI event. */ public void dispatchNextGuiEvent() throws InterruptedException { EventQueue queue = awtEventQueue; if (queue == null) { queue = Toolkit.getDefaultToolkit().getSystemEventQueue(); awtEventQueue = queue; } AWTEvent event = queue.getNextEvent(); if (event instanceof ActiveEvent) { ((ActiveEvent)event).dispatch(); } else { Object source = event.getSource(); if (source instanceof Component) { Component comp = (Component)source; comp.dispatchEvent(event); } else if (source instanceof MenuComponent) { ((MenuComponent)source).dispatchEvent(event); } } }
Example 4
Source File: ExtTestCase.java From netbeans with Apache License 2.0 | 5 votes |
/** Drain the event queue. ONLY CALL THIS METHOD FROM THE EVENT DISPATCH * THREAD OR IT WILL DO BAD THINGS! */ private static void drainEventQueue() throws Exception { AWTEvent evt = EventQueue.getCurrentEvent(); //Dispatch any events that the code that just ran may have generated, //so dialogs appear, things get focus and paint, stuff like that while (Toolkit.getDefaultToolkit().getSystemEventQueue().peekEvent() != null) { //do fetch this every time, its value can change EventQueue queue = Toolkit.getDefaultToolkit().getSystemEventQueue(); evt = queue.getNextEvent(); dispatchEvent(queue, evt); } }
Example 5
Source File: Swing.java From pdfxtk with Apache License 2.0 | 4 votes |
public static void startModal(javax.swing.JInternalFrame f) { synchronized(f) { /* Since all input will be blocked until this dialog is dismissed, * make sure its parent containers are visible first (this component * is tested below). This is necessary for JApplets, because * because an applet normally isn't made visible until after its * start() method returns -- if this method is called from start(), * the applet will appear to hang while an invisible modal frame * waits for input. */ if (f.isVisible() && !f.isShowing()) { Container parent = f.getParent(); while (parent != null) { if (parent.isVisible() == false) { parent.setVisible(true); } parent = parent.getParent(); } } try { if (SwingUtilities.isEventDispatchThread()) { EventQueue theQueue = f.getToolkit().getSystemEventQueue(); while (f.isVisible()) { // This is essentially the body of EventDispatchThread AWTEvent event = theQueue.getNextEvent(); Object src = event.getSource(); // can't call theQueue.dispatchEvent, so I pasted it's 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 { System.err.println("unable to dispatch event: " + event); } } } else while (f.isVisible()) f.wait(); } catch(InterruptedException e){} } }