Example usage for java.awt.event KeyEvent getKeyCode

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

Introduction

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

Prototype

public int getKeyCode() 

Source Link

Document

Returns the integer keyCode associated with the key in this event.

Usage

From source file:KeyTextComponent.java

public KeyTextComponent() {
    setBackground(Color.CYAN);/*from  w w  w. j  a v  a2s .  c o m*/
    KeyListener internalKeyListener = new KeyAdapter() {
        public void keyPressed(KeyEvent keyEvent) {
            if (actionListenerList != null) {
                int keyCode = keyEvent.getKeyCode();
                String keyText = KeyEvent.getKeyText(keyCode);
                ActionEvent actionEvent = new ActionEvent(this, ActionEvent.ACTION_PERFORMED, keyText);
                actionListenerList.actionPerformed(actionEvent);
            }
        }
    };
    MouseListener internalMouseListener = new MouseAdapter() {
        public void mousePressed(MouseEvent mouseEvent) {
            requestFocusInWindow();
        }
    };
    addKeyListener(internalKeyListener);
    addMouseListener(internalMouseListener);
}

From source file:MyButtonUI.java

public void keyPressed(KeyEvent e) {
    int code = e.getKeyCode();
    if (code == KeyEvent.VK_ENTER || code == KeyEvent.VK_SPACE) {
        JComponent c = (JComponent) e.getComponent();
        c.setBorder(m_borderLowered);//from ww w . j ava2 s . co  m
        c.setBackground(m_backgroundPressed);
    }
}

From source file:MyButtonUI.java

public void keyReleased(KeyEvent e) {
    int code = e.getKeyCode();
    if (code == KeyEvent.VK_ENTER || code == KeyEvent.VK_SPACE) {
        JComponent c = (JComponent) e.getComponent();
        c.setBorder(m_borderRaised);// w ww. java2 s . c  o m
        c.setBackground(m_backgroundNormal);
    }
}

From source file:Main.java

public void keyPressed(KeyEvent evt) {
    if (evt.getKeyChar() == 'a') {
        System.out.println("Check for key characters: " + evt.getKeyChar());
    }//w w  w .j a v  a2 s  . co  m
    if (evt.getKeyCode() == KeyEvent.VK_HOME) {
        System.out.println("Check for key codes: " + evt.getKeyCode());
    }
}

From source file:Main.java

public void keyTyped(KeyEvent evt) {
    if (evt.getKeyChar() == 'a') {
        System.out.println("Check for key characters: " + evt.getKeyChar());
    }//from  w  w  w.  jav a2 s.  com
    if (evt.getKeyCode() == KeyEvent.VK_HOME) {
        System.out.println("Check for key codes: " + evt.getKeyCode());
    }
}

From source file:Main.java

public void keyReleased(KeyEvent evt) {
    if (evt.getKeyChar() == 'a') {
        System.out.println("Check for key characters: " + evt.getKeyChar());
    }// ww  w  .  j  a  v a 2s  .  c  o  m
    if (evt.getKeyCode() == KeyEvent.VK_HOME) {
        System.out.println("Check for key codes: " + evt.getKeyCode());
    }
}

From source file:Main.java

public KeyTextComponent() {
    setBackground(Color.cyan);/* w  ww  .j  av  a 2  s  . co  m*/
    KeyListener internalKeyListener = new KeyAdapter() {
        public void keyPressed(KeyEvent keyEvent) {
            if (actionListenerList != null) {
                int keyCode = keyEvent.getKeyCode();
                String keyText = KeyEvent.getKeyText(keyCode);
                ActionEvent actionEvent = new ActionEvent(this, ActionEvent.ACTION_PERFORMED, keyText);
                actionListenerList.actionPerformed(actionEvent);
            }
        }
    };

    MouseListener internalMouseListener = new MouseAdapter() {
        public void mousePressed(MouseEvent mouseEvent) {
            requestFocus();
        }
    };

    addKeyListener(internalKeyListener);
    addMouseListener(internalMouseListener);
}

From source file:MainClass.java

public KeyTextComponent() {
    setBackground(Color.CYAN);/*from ww  w.ja  v a  2  s. com*/
    KeyListener internalKeyListener = new KeyAdapter() {
        public void keyPressed(KeyEvent keyEvent) {
            if (actionListenerList != null) {
                int keyCode = keyEvent.getKeyCode();
                String keyText = KeyEvent.getKeyText(keyCode);
                ActionEvent actionEvent = new ActionEvent(this, ActionEvent.ACTION_PERFORMED, keyText);
                fireActionPerformed(actionEvent);
            }
        }
    };

    MouseListener internalMouseListener = new MouseAdapter() {
        public void mousePressed(MouseEvent mouseEvent) {
            requestFocusInWindow();
        }
    };

    addKeyListener(internalKeyListener);
    addMouseListener(internalMouseListener);
}

From source file:Main.java

public KeyTextComponent() {
    setBackground(Color.CYAN);/*www  .j  a v  a 2  s .  co m*/
    KeyListener internalKeyListener = new KeyAdapter() {
        public void keyPressed(KeyEvent keyEvent) {
            if (actionListenerList != null) {
                int keyCode = keyEvent.getKeyCode();
                String keyText = KeyEvent.getKeyText(keyCode);
                ActionEvent actionEvent = new ActionEvent(this, ActionEvent.ACTION_LAST, keyText);
                fireActionPerformed(actionEvent);
            }
        }
    };

    MouseListener internalMouseListener = new MouseAdapter() {
        public void mousePressed(MouseEvent mouseEvent) {
            requestFocusInWindow();
        }
    };

    addKeyListener(internalKeyListener);
    addMouseListener(internalMouseListener);
}

From source file:KeyTextTester2.java

public KeyTextComponent2() {
    setBackground(Color.cyan);/* ww  w .ja va2s .  c  o m*/
    KeyListener internalKeyListener = new KeyAdapter() {
        public void keyPressed(KeyEvent keyEvent) {
            if (actionListenerList != null) {
                int keyCode = keyEvent.getKeyCode();
                String keyText = KeyEvent.getKeyText(keyCode);
                ActionEvent actionEvent = new ActionEvent(this, ActionEvent.ACTION_PERFORMED, keyText);
                fireActionPerformed(actionEvent);
            }
        }
    };

    MouseListener internalMouseListener = new MouseAdapter() {
        public void mousePressed(MouseEvent mouseEvent) {
            requestFocus();
        }
    };

    addKeyListener(internalKeyListener);
    addMouseListener(internalMouseListener);
}