0

Basically I have 2 JFrame windows, one of which contains an applet. I am trying to send the key typed to the applet.

@Override
public void keyReleased(KeyEvent e) {
    dispatchKeyTyped(e.getID(),e.getModifiers(),e.getKeyCode(),e.getKeyChar(),e.getKeyLocation());
}

@Override
public void keyTyped(KeyEvent e) {
    dispatchKeyTyped(e.getID(),e.getModifiers(),e.getKeyCode(),e.getKeyChar(),e.getKeyLocation());
} 

public void dispatchKeyTyped(int id, int modifiers, int keycode, char keychar, int keylocation) {
    applet.getComponent(0).dispatchEvent(new KeyEvent(applet,id,System.currentTimeMillis(),modifiers,keycode,keychar,keylocation));
}

When I try to do this nothing happens, the key is not send. If I replace the code by sending the KeyEvent like this:

@Override
public void keyReleased(KeyEvent e) {
    dispatchKeyTyped(e);
}

@Override
public void keyTyped(KeyEvent e) {
    dispatchKeyTyped(e);
} 
public void dispatchKeyTyped(KeyEvent event) {
    applet.getComponent(0).dispatchEvent(event);
}

This seems to work fine but I want to create the KeyEvent myself and not sure why the first example does not work.

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
Rvdrichard
  • 335
  • 3
  • 12

0 Answers0