Example usage for java.awt.event KeyEvent VK_DOWN

List of usage examples for java.awt.event KeyEvent VK_DOWN

Introduction

In this page you can find the example usage for java.awt.event KeyEvent VK_DOWN.

Prototype

int VK_DOWN

To view the source code for java.awt.event KeyEvent VK_DOWN.

Click Source Link

Document

Constant for the non-numpad down arrow key.

Usage

From source file:Main.java

private static boolean isNonEditKey(int keyCode) {
    switch (keyCode) {
    case KeyEvent.VK_UP:
    case KeyEvent.VK_DOWN:
    case KeyEvent.VK_LEFT:
    case KeyEvent.VK_RIGHT:
    case KeyEvent.VK_CAPS_LOCK:
    case KeyEvent.VK_CONTROL:
    case KeyEvent.VK_ALT:
    case KeyEvent.VK_SHIFT:
    case KeyEvent.VK_INSERT:
    case KeyEvent.VK_HOME:
    case KeyEvent.VK_END:
    case KeyEvent.VK_PAGE_DOWN:
    case KeyEvent.VK_PAGE_UP:
    case KeyEvent.VK_PRINTSCREEN:
    case KeyEvent.VK_NUM_LOCK:
    case KeyEvent.VK_ESCAPE:
        return true;
    }//  w w  w  .ja  va  2s.com
    if (keyCode >= KeyEvent.VK_F1 && keyCode <= KeyEvent.VK_F12) {
        return true;
    }
    return false;
}

From source file:Main.java

public static boolean isArrowKey(int keyCode) {
    return KeyEvent.VK_LEFT <= keyCode && keyCode <= KeyEvent.VK_DOWN
            || KeyEvent.VK_KP_UP <= keyCode && keyCode <= KeyEvent.VK_KP_RIGHT;
}

From source file:Main.java

public void keyPressed(KeyEvent evt) {
    int keyCode = evt.getKeyCode();
    int d;/*from  ww  w  .  j a  va2  s  .c o  m*/
    if (evt.isShiftDown()) {
        System.out.println("shift down");
    }
    if (keyCode == KeyEvent.VK_LEFT)
        System.out.println("KeyEvent.VK_LEFT");
    else if (keyCode == KeyEvent.VK_RIGHT)
        System.out.println("KeyEvent.VK_RIGHT");
    else if (keyCode == KeyEvent.VK_UP)
        System.out.println("KeyEvent.VK_UP");
    else if (keyCode == KeyEvent.VK_DOWN)
        System.out.println("KeyEvent.VK_DOWN");
}

From source file:Main.java

public void keyPressed(KeyEvent evt) {
    int keyCode = evt.getKeyCode();
    int d;/*ww w  .  j  a v a  2 s.  co  m*/
    if (evt.isShiftDown())
        d = 5;
    else
        d = 1;
    if (keyCode == KeyEvent.VK_LEFT)
        add(-d, 0);
    else if (keyCode == KeyEvent.VK_RIGHT)
        add(d, 0);
    else if (keyCode == KeyEvent.VK_UP)
        add(0, -d);
    else if (keyCode == KeyEvent.VK_DOWN)
        add(0, d);
}

From source file:mainDraw.java

public void keyReleased(KeyEvent e) {
    if (e.getKeyCode() == KeyEvent.VK_RIGHT)
        draw.moveRight();//from   w w w. j  av  a 2s  .c om
    else if (e.getKeyCode() == KeyEvent.VK_LEFT)
        draw.moveLeft();
    else if (e.getKeyCode() == KeyEvent.VK_DOWN)
        draw.moveDown();
    else if (e.getKeyCode() == KeyEvent.VK_UP)
        draw.moveUp();

}

From source file:Main.java

@Override
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected,
        boolean cellHasFocus) {
    super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
    if (comboList == null) {
        comboList = list;//from  ww  w. j  a  v a 2  s .com
        KeyAdapter listener = new KeyAdapter() {

            @Override
            public void keyReleased(KeyEvent e) {
                if (e.getKeyCode() == KeyEvent.VK_DOWN || e.getKeyCode() == KeyEvent.VK_UP) {
                    int x = 5;
                    int y = comboList.indexToLocation(comboList.getSelectedIndex()).y;
                    System.out.println(comboList.getSelectedIndex());
                }
            }
        };
        combo.addKeyListener(listener);
        combo.getEditor().getEditorComponent().addKeyListener(listener);
    }
    if (isSelected) {
        System.out.println(value.toString());
    }
    return this;
}

From source file:spypunk.tetris.ui.controller.input.TetrisControllerInputHandlerImpl.java

@Inject
public TetrisControllerInputHandlerImpl(final TetrisControllerCommandFactory tetrisControllerCommandFactory) {
    pressedKeyCodesHandlers.put(KeyEvent.VK_LEFT,
            () -> tetrisControllerCommandFactory.createMovementTetrisControllerCommand(Movement.LEFT));

    pressedKeyCodesHandlers.put(KeyEvent.VK_RIGHT,
            () -> tetrisControllerCommandFactory.createMovementTetrisControllerCommand(Movement.RIGHT));

    pressedKeyCodesHandlers.put(KeyEvent.VK_DOWN,
            () -> tetrisControllerCommandFactory.createMovementTetrisControllerCommand(Movement.DOWN));

    releasedKeyCodesHandlers.put(KeyEvent.VK_SPACE,
            tetrisControllerCommandFactory::createNewGameTetrisControllerCommand);

    releasedKeyCodesHandlers.put(KeyEvent.VK_P,
            tetrisControllerCommandFactory::createPauseTetrisControllerCommand);

    releasedKeyCodesHandlers.put(KeyEvent.VK_UP,
            () -> tetrisControllerCommandFactory.createMovementTetrisControllerCommand(Movement.ROTATE_CW));

    releasedKeyCodesHandlers.put(KeyEvent.VK_M,
            tetrisControllerCommandFactory::createMuteTetrisControllerCommand);

    releasedKeyCodesHandlers.put(KeyEvent.VK_PAGE_UP,
            tetrisControllerCommandFactory::createIncreaseVolumeTetrisControllerCommand);

    releasedKeyCodesHandlers.put(KeyEvent.VK_PAGE_DOWN,
            tetrisControllerCommandFactory::createDecreaseVolumeTetrisControllerCommand);

    releasedKeyCodesHandlers.put(KeyEvent.VK_CONTROL,
            tetrisControllerCommandFactory::createHardDropTetrisControllerCommand);
}

From source file:com.konifar.material_icon_generator.FilterComboBox.java

private void initListener() {
    final JTextField textfield = (JTextField) this.getEditor().getEditorComponent();
    textfield.addKeyListener(new KeyAdapter() {
        public void keyReleased(KeyEvent event) {
            switch (event.getKeyCode()) {
            case KeyEvent.VK_ENTER:
            case KeyEvent.VK_ESCAPE:
                requestFocus(false);//from   w  w  w  .j a  v a2 s . c o m
                break;
            case KeyEvent.VK_UP:
            case KeyEvent.VK_DOWN:
                break;
            default:
                SwingUtilities.invokeLater(new Runnable() {
                    public void run() {
                        filter(textfield.getText());
                    }
                });
            }
        }
    });

    getAccessibleContext().addPropertyChangeListener(new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent event) {
            if (AccessibleContext.ACCESSIBLE_STATE_PROPERTY.equals(event.getPropertyName())
                    && AccessibleState.FOCUSED.equals(event.getNewValue())
                    && getAccessibleContext().getAccessibleChild(0) instanceof ComboPopup) {
                ComboPopup popup = (ComboPopup) getAccessibleContext().getAccessibleChild(0);
                JList list = popup.getList();

                if (list.getSelectedValue() != null) {
                    setSelectedItem(String.valueOf(list.getSelectedValue()));
                }
            }
        }
    });
}

From source file:edu.mit.fss.tutorial.part4.ControlPanel.java

/**
 * Instantiates a new control panel.//from ww w . ja  va  2s  .  c o m
 */
public ControlPanel() {
    setFocusable(true); // required for key listener
    setPreferredSize(new Dimension(300, 300));
    setBackground(Color.white);

    // Add a new KeyAdapter object instance to bind actions to key presses.
    addKeyListener(new KeyAdapter() {
        @Override
        public void keyPressed(KeyEvent e) {
            if (boundElement == null) {
                // Do nothing if no element is bound.
                return;
            }
            if (e.getKeyCode() == KeyEvent.VK_UP) {
                // Increment Y-velocity.
                boundElement.setVelocity(boundElement.getVelocity().add(new Vector3D(0, 1, 0)));
            } else if (e.getKeyCode() == KeyEvent.VK_DOWN) {
                // Decrement Y-velocity.
                boundElement.setVelocity(boundElement.getVelocity().add(new Vector3D(0, -1, 0)));
            } else if (e.getKeyCode() == KeyEvent.VK_LEFT) {
                // Decrement X-velocity.
                boundElement.setVelocity(boundElement.getVelocity().add(new Vector3D(-1, 0, 0)));
            } else if (e.getKeyCode() == KeyEvent.VK_RIGHT) {
                // Increment X-velocity.
                boundElement.setVelocity(boundElement.getVelocity().add(new Vector3D(1, 0, 0)));
            }
        }
    });
}

From source file:org.jcodec.player.app.PlayerMain.java

public void keyPressed(KeyEvent e) {
    if (e.getKeyCode() == KeyEvent.VK_SPACE) {
        if (player.getStatus() == Player.Status.PAUSED) {
            if (stepper != null) {
                player.seek(stepper.getPos());
                stepper = null;/*from   w  ww. ja  va2 s  .  c om*/
            }
            player.play();
        } else
            player.pause();
    } else if (e.getKeyCode() == KeyEvent.VK_DOWN) {
        RationalLarge pos = player.getPos();
        player.seek(new RationalLarge(pos.getNum() - pos.getDen() * 15, pos.getDen()));
    } else if (e.getKeyCode() == KeyEvent.VK_UP) {
        RationalLarge pos = player.getPos();
        player.seek(new RationalLarge(pos.getNum() + pos.getDen() * 15, pos.getDen()));
    } else if (e.getKeyCode() == KeyEvent.VK_LEFT) {
        // if (player.getStatus() != Player.Status.PAUSED) {
        // player.pause();
        // return;
        // }
        //
        // try {
        // if (stepper == null) {
        // stepper = new Stepper(video, mixer, vo, new JSoundAudioOut());
        // stepper.setListeners(player.getListeners());
        // stepper.gotoFrame(player.getFrameNo());
        // }
        // stepper.prev();
        // } catch (IOException e1) {
        // System.out.println("Couldn't step " + e1.getMessage());
        // }
    } else if (e.getKeyCode() == KeyEvent.VK_RIGHT) {
        if (player.getStatus() != Player.Status.PAUSED) {
            player.pause();
            return;
        }
        try {
            if (stepper == null) {
                stepper = new Stepper(video, mixer, vo, new JSoundAudioOut());
                stepper.setListeners(player.getListeners());
                stepper.gotoFrame(player.getFrameNo());
            }
            stepper.next();
        } catch (IOException e1) {
            System.out.println("Couldn't step " + e1.getMessage());
        }
    } else if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
        player.destroy();
        System.exit(-1);
    } else if (e.getKeyChar() >= '0' && e.getKeyChar() < '9') {
        int ch = e.getKeyChar() - '0';
        for (Pin pin : mixer.getPins()) {
            if (ch < pin.getLabels().length) {
                pin.toggle(ch);
                break;
            } else
                ch -= pin.getLabels().length;
        }
    }
}