import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class KeyCode extends JFrame implements KeyListener {
String msg="";
int x=10,y=20;
JTextArea txt=new JTextArea();
public KeyCode()
{
add(txt);
txt.setEnabled(false);
addKeyListener(this);
setSize(200,300);
setVisible(true);
}
public void keyTyped(KeyEvent e)
{
msg+=e.getKeyChar();
setTitle("Key pressed");
txt.setText(msg);
}
public void keyPressed(KeyEvent e)
{
setTitle("Key pressed");
int key=e.getKeyCode();
switch(key){
case KeyEvent.VK_F1:
msg+="<F1>";
break;
case KeyEvent.VK_F2:
msg+="<F2>";
break;
case KeyEvent.VK_F3:
msg+="<F3>";
break;
case KeyEvent.VK_F4:
msg+="<F4>";
break;
case KeyEvent.VK_F5:
msg+="<F5>";
break;
case KeyEvent.VK_F6:
msg+="<F6>";
break;
case KeyEvent.VK_F7:
msg+="<F7>";
break;
case KeyEvent.VK_F8:
msg+="<F8>";
break;
case KeyEvent.VK_F9:
msg+="<F9>";
break;
case KeyEvent.VK_F10:
msg+="<F10>";
break;
case KeyEvent.VK_PAGE_DOWN:
msg+="<pgdn>";
break;
case KeyEvent.VK_PAGE_UP:
msg+="<pgup>";
break;
case KeyEvent.VK_LEFT:
msg+="<left arrow>";
break;
case KeyEvent.VK_RIGHT:
msg+="<right arrow>";
break;
case KeyEvent.VK_UP:
msg+="<Uper arrow>";
break;
case KeyEvent.VK_DOWN:
msg+="<down arrow>";
break;
}
txt.setText(msg);
repaint();
}
public void keyReleased(KeyEvent e)
{
setTitle("Key Released");
}
public static void main(String args[])
{
KeyCode bt = new KeyCode();
bt.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE );
}
}