class KeyDemoFrame extends JFrame implements KeyListener
{
String line1;
KeyDemoFrame()
{
setTitle("hello");
setSize(200,200);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
addKeyListener(this);
}
public void keyTyped(KeyEvent e) {
line1 = e.getKeyText(e.getKeyCode());
JOptionPane.showMessageDialog(null, e.getKeyCode());
JOptionPane.showMessageDialog(null, e.getKeyText(e.getKeyCode()));
}
public void keyPressed(KeyEvent e) {
}
public void keyReleased(KeyEvent e) {
}
}
When I press any key, I get "0" for the first message dialog and "Unknown keyCode:0x0" for the second one.
What am I doing wrong?