Trouble Converting Application to applet
Hi, i have a simple Snake game i programmed as an application. Now i want to convert it to an applet in the standard way. All is fine and dandy except the key listeners no longer work. Why is this and why would an applet behave differently to the application?
the code for the KeyHandler:
import java.awt.event.*;
public class KeyHandler extends KeyAdapter {
public KeyHandler(GamePane controller) {
this.controller = controller;
System.out.println("key handler created");
}
public void keyPressed(KeyEvent e) { System.out.println("key pressed");
int keyCode = e.getKeyCode();
controller.moveMade(keyCode);
}
private GamePane controller;
}
In the main JApplet class, this is how it is added:
addKeyListener(new KeyHandler(gamePane));
The message that the keyHandler has been created is received, but there is never any message so say that a key has been pressed. No exception occur and the applet is in focus.
Many thanks
|