Example usage for java.awt.event KeyEvent VK_LEFT

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

Introduction

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

Prototype

int VK_LEFT

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

Click Source Link

Document

Constant for the non-numpad left 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;
    }//from  w w w.j  a  va 2  s  .c om
    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 w w w .ja v a2 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;//from w  w  w .  j a v  a  2  s . c  o  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 ww.j a  va  2s .c  o  m
    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:TextLayoutWithCarets.java

public TextLayoutWithCarets() {
    addKeyListener(new KeyListener() {
        public void keyPressed(KeyEvent ke) {
            if (ke.getKeyCode() == KeyEvent.VK_RIGHT) {
                mHit = mLayout.getNextRightHit(mHit.getInsertionIndex());
                if (mHit == null)
                    mHit = mLayout.getNextLeftHit(1);
                repaint();/*  w w w . j  a v a2s  . com*/
            } else if (ke.getKeyCode() == KeyEvent.VK_LEFT) {
                mHit = mLayout.getNextLeftHit(mHit.getInsertionIndex());
                if (mHit == null)
                    mHit = mLayout.getNextRightHit(mLayout.getCharacterCount() - 1);
                repaint();
            }
        }

        public void keyTyped(KeyEvent arg0) {
            // TODO Auto-generated method stub

        }

        public void keyReleased(KeyEvent arg0) {
            // TODO Auto-generated method stub

        }
    });

}

From source file:ImageSorter.java

/**
 * @param in/*from  www  . java 2 s . c om*/
 * @param leftOut
 * @param rightOut
 */
public ImageSorter(String in, String leftOut, String rightOut) {
    super("ImageSorter");

    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    inputs = new File(in).listFiles(new FilenameFilter() {

        @Override
        public boolean accept(File dir, String name) {
            String s = name.toLowerCase();

            return s.endsWith("jpg");
        }

    });

    leftOutput = new File(in, leftOut);
    rightOutput = new File(in, rightOut);

    leftOutput.mkdirs();
    rightOutput.mkdirs();

    assert leftOutput.canWrite();
    assert rightOutput.canWrite();

    panel.setPreferredSize(new Dimension(640, 480));
    getContentPane().setLayout(new BorderLayout());
    getContentPane().add(panel, BorderLayout.CENTER);

    panel.addKeyListener(new KeyAdapter() {

        @Override
        public void keyReleased(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_RIGHT) {
                inputs[index].renameTo(new File(rightOutput, inputs[index].getName()));
            } else if (e.getKeyCode() == KeyEvent.VK_LEFT) {
                inputs[index].renameTo(new File(leftOutput, inputs[index].getName()));
            }

            nextImage();
        }

    });

    panel.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseReleased(MouseEvent e) {
            panel.requestFocusInWindow();
        }

        @Override
        public void mousePressed(MouseEvent e) {
            panel.requestFocusInWindow();
        }

        @Override
        public void mouseEntered(MouseEvent e) {
            panel.requestFocusInWindow();
        }

        @Override
        public void mouseClicked(MouseEvent e) {
            panel.requestFocusInWindow();
        }

    });

    panel.requestFocusInWindow();

    nextImage();

    pack();
    setVisible(true);
}

From source file:net.sf.maltcms.chromaui.charts.events.DomainMarkerKeyListener.java

@Override
public void keyTyped(KeyEvent e) {
    double oldPos = xyp.getDomainCrosshairValue();
    if (e.getKeyCode() == KeyEvent.VK_RIGHT) {
        xyp.setDomainCrosshairValue(oldPos++);
        //            xyp.getDataset().get
        //            final IEvent<XYItemEntity> v = new XYItemEntityClickedEvent();
        //            fireEvent(v);
    }/*from   w w w  . j a v a  2 s .  c  om*/
    if (e.getKeyCode() == KeyEvent.VK_LEFT) {
        xyp.setDomainCrosshairValue(oldPos--);
    }
}

From source file:de.tor.tribes.ui.components.GroupSelectionList.java

public GroupSelectionList(String pResourceURL) {
    super(pResourceURL);

    setCellRenderer(renderer);//from   w  w w  . ja  va2 s .c  o  m

    addKeyListener(new KeyAdapter() {

        @Override
        public void keyReleased(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_LEFT) {
                fireDecrementEvent();
            } else if (e.getKeyCode() == KeyEvent.VK_RIGHT) {
                fireIncrementEvent();
            } else if (e.getKeyCode() == KeyEvent.VK_DELETE) {
                fireResetEvent();
            } else if (e.getKeyCode() == KeyEvent.VK_O) {
                fireSetStateEvent(ListItem.RELATION_TYPE.OR);
            } else if (e.getKeyCode() == KeyEvent.VK_U) {
                fireSetStateEvent(ListItem.RELATION_TYPE.AND);
            } else if (e.getKeyCode() == KeyEvent.VK_N) {
                fireSetStateEvent(ListItem.RELATION_TYPE.NOT);
            } else if (e.getKeyCode() == KeyEvent.VK_I) {
                fireSetStateEvent(ListItem.RELATION_TYPE.DISABLED);
            } else if (e.getKeyCode() == KeyEvent.VK_H) {
                JOptionPaneHelper.showInformationBox(GroupSelectionList.this, getRelationAsPlainText(),
                        "Information");
            }
        }
    });
    addMouseListener(new MouseAdapter() {

        @Override
        public void mouseClicked(MouseEvent e) {
            if (e.getClickCount() == 2) {
                if (e.getButton() == MouseEvent.BUTTON1) {
                    fireClickedEvent(e.getPoint());
                } else {
                    fireResetEvent(e.getPoint());
                }
            }
        }
    });
    TagManager.getSingleton().addManagerListener(GroupSelectionList.this);
}

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

/**
 * Instantiates a new control panel.//  w  ww  . j av a2 s .  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)));
            }
        }
    });
}