Hellow!
I am dealing with keyboard listener in MVC pattern.
I would like to make a controller with ActionListner and KeyListener.
public class ArtillaryTankController implements ActionListener, KeyListener {
public void actionPerformed( ActionEvent e) {
....
}
public void keyPressed(KeyEvent e) {
System.out.println("Key Pressed");
if (e.getKeyCode() == KeyEvent.VK_KP_LEFT)
System.out.println("Left_Arrow_Key Pressed");
if (e.getKeyCode() == KeyEvent.VK_KP_RIGHT)
System.out.println("Right_Arrow_Key Pressed");
}
public void keyTyped(KeyEvent e) {
System.out.println("Key Typed");
}
public void keyReleased(KeyEvent e) {
System.out.println("Key Released");
}
}
public class ArtillaryTankWorldPanel extends JPanel {
....
}
public class ArtillaryTankFrame extends JFrame {
....
_artillaryTankWorldPanel =new ArtillaryTankWorldPanel(_frameWidth, _frameHeight);
final ArtillaryTankController controller = new ArtillaryTankController(_artillaryTankWorldPanel);
....
_artillaryTankWorldPanel.addKeyListener(controller);
....
}
The ActionListeners works fine, but the KeyListener does not work. I can't see any message.
Please, guide me to find the right way.
Thanks for reading.
Sincerely yours