-
Bug
-
Resolution: Not an Issue
-
P4
-
None
-
1.1, 1.1.4, 1.2.0
-
x86, sparc
-
solaris_2.5.1, solaris_2.6, windows_95
Name: mc57594 Date: 02/26/97
When a key is typed on a textfield, the getKeyCode() method
returns 0 in keyTyped().
public void keyTyped(KeyEvent e) {
System.out.println("KeyCode: " + e.getKeyText(e.getKeyCode()));
}
Following line is printed as a key is typed:
KeyCode: Unknown keyCode: 0x0
company - Aegis Software Inc. , email - ###@###.###
======================================================================
Name: diC59631 Date: 1997-11-24
Here is a complete test case. The problem still exists on win32 and solraris
with jdk1.1.5j.
import java.awt.event.*;
import java.awt.*;
public class KeyTest2 extends Frame implements ActionListener, KeyListener {
List testList;
TextField tf;
public KeyTest2(){
super("Key Test Frame");
setLayout(new FlowLayout());
Button testButton = new Button("Test");
add(testButton);
testButton.addActionListener(this);
testList = new List();
testList.addKeyListener(this);
testList.addItem("dog");
testList.addItem("cat");
testList.addItem("bird");
testList.addItem("mouse");
testList.addItem("skunk");
//testList.setMultipleMode(true);
testList.setMultipleMode(false);
add(testList);
tf = new TextField(10);
tf.addKeyListener(this);
add(tf);
pack();
}
public void keyPressed(KeyEvent e) {
if (e.getKeyCode()==e.VK_LEFT) {
int a = testList.getSelectedIndex();
testList.select(a);
System.out.println("key pressed " + a);
} else {
e.setKeyChar(Character.toUpperCase(e.getKeyChar()));
System.out.println("keyPressed " + e.getKeyCode() + " " + e.getKeyText(e.getKeyCode()) + " " + e.getKeyChar());
}
}
public void keyTyped(KeyEvent e) {
System.out.println("keyTyped " + e.getKeyCode() + " " + e.getKeyText(e.getKeyCode()) + " " + e.getKeyChar());
}
public void keyReleased(KeyEvent e) {
if (e.getKeyCode()==e.VK_LEFT) {
int a = testList.getSelectedIndex();
testList.select(a);
System.out.println("key released " + a);
}
System.out.println("keyReleased " + e.getKeyCode() + " " + e.getKeyText(e.getKeyCode()) + " " + e.getKeyChar());
}
public void actionPerformed(ActionEvent evt) {
int a = testList.getSelectedIndex();
testList.select(a);
System.out.println(a);
}
public static void main(String args[]){
KeyTest2 myTest = new KeyTest2();
myTest.show();
}
}