-5

I have a JFrame that has two panels, the first panel(panel) has buttons and labels only, where the second panel has the game and keyboard input . The second panel(panelGame) does appear on screen, but with no keyboard response, my space ship cannot move nor I can shoot. Please download my project and help me thank you for your time and consideration.

https://www.mediafire.com/?wjz6fm3z4567bq8

Sitansu
  • 3,225
  • 8
  • 34
  • 61

1 Answers1

3

From the description of the problem, the likely cause is you are using a KeyListener of some kind

The problem with this is, a KeyListener will only be notified of key events when the component it is registered to has key board focus AND is focusable.

A better solution would be to use Key Bindings which allow you to control at what focus level the bindings should be triggered.

trashgod
  • 203,806
  • 29
  • 246
  • 1,045
MadProgrammer
  • 343,457
  • 22
  • 230
  • 366