import java.awt.*;
import java.awt.event.*;
import java.applet.*;
/*
<applet code="KeyCode" width=300 height=100>
</applet>
*/
public class KeyCode extends Applet {
String msg="";
int x=10,y=20;
public void init()
{
addKeyListener(new KeyAdpt());
requestFocus();
}
private class KeyAdpt extends KeyAdapter
{
public void keyPressed(KeyEvent e)
{
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;
}
repaint();
}
public void keyTyped(KeyEvent ke)
{
msg += ke.getKeyChar();
repaint();
}
}
public void paint(Graphics g)
{
g.drawString(msg,x,y);
}
}