Hi,
I have question about typing "TAB" key in
Java Applet in internet explorer with JRE 1.05_08 or above.
When I type any key other than "TAB", the function, processEvent, will be called 3 times to process keyPressed, keyTyped and keyReleased. However, when I type "TAB" key, processEvent is only called once to process keyTyped and the focus goes outside the applet.
Is there any way that the focus won't get lost when typing the "TAB" key?
Note that this problem only happens in IE browser with JRE 1.05_08 or above. It works well in Firefox and netscape with any JRE version and works well in IE with JRE 1.05_06 and below.
The following is my code:
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class KeyEventDemo extends Applet implements KeyListener, FocusListener {
public KeyEventDemo() {
super();
addKeyListener(this);
addFocusListener(this);
}
public void keyTyped(KeyEvent e) {
System.out.println("KEY TYPED: e="+e);
}
public void keyPressed(KeyEvent e) {
System.out.println("KEY PRESSED: e="+e);
}
public void keyReleased(KeyEvent e) {
System.out.println("KEY RELEASED: e="+e);
}
public boolean keyDown(Event e, int key) {
System.out.println("keyDown: e="+e);
return false;
}
public boolean keyUp(Event e, int key) {
System.out.println("keyUp: e="+e);
return false;
}
public void processEvent(AWTEvent e) {
System.out.println("processEvent : e="+e);
}
public void focusGained(FocusEvent e){System.out.println("FocusGained");}
public void focusLost(FocusEvent e){System.out.println("FocusLost");}
public void paint ( Graphics g ){
this.setBackground ( Color.blue );
}
public boolean isFocusTraversable() {
return true;
}
public boolean getFocusTraversalKeysEnabled() {
return false;
}
}
Thanks very much!