Java KeyAdapter .keyReleased (KeyEvent e)

Syntax

KeyAdapter.keyReleased(KeyEvent e) has the following syntax.

public void keyReleased(KeyEvent e)

Example

In the following code shows how to use KeyAdapter.keyReleased(KeyEvent e) method.


//w ww  . j  ava2  s  .co m
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;

import javax.swing.JFrame;
import javax.swing.JTextField;

public class Main {
  public static void main(String[] argv) throws Exception {
    JTextField component = new JTextField();
    component.addKeyListener(new MyKeyListener());

    JFrame f = new JFrame();

    f.add(component);
    f.setSize(300, 300);
    f.setVisible(true);

  }
}

class MyKeyListener extends KeyAdapter {
  public void keyReleased(KeyEvent evt) {
    if (evt.getKeyChar() == 'a') {
      System.out.println("Check for key characters: " + evt.getKeyChar());
    }
    if (evt.getKeyCode() == KeyEvent.VK_HOME) {
      System.out.println("Check for key codes: " + evt.getKeyCode());
    }
  }
}




















Home »
  Java Tutorial »
    java.awt.event »




AdjustmentListener
ActionEvent
ActionListener
HierarchyEvent
HierarchyListener
InputEvent
ItemEvent
ItemListener
KeyAdapter
KeyEvent
KeyListener
MouseAdapter
MouseEvent
MouseListener
MouseMotionAdapter
MouseMotionListener
MouseWheelEvent
MouseWheelListener
WindowAdapter
WindowEvent
WindowFocusListener
WindowStateListener