Code example for ConcurrentLinkedQueue

Methods: add

0
    public boolean dispatchKeyEvent(KeyEvent e) { 
        if (e.getID() == KeyEvent.KEY_PRESSED) { 
            if (e.getKeyCode() == KeyEvent.VK_SPACE) { 
                e.consume(); 
            } 
            keyEventQueue.add(new InputEvent(e, System.nanoTime())); 
        } 
        return false; 
    } 
 
    public Collection<InputEvent> getAndRemoveAll() { 
        Collection<InputEvent> c = new ArrayList<InputEvent>(keyEventQueue); 
        keyEventQueue.removeAll(c); 
        return c; 
    } 
}