-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,145
  • 7
  • 31
  • 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
  • 200,320
  • 28
  • 229
  • 974
MadProgrammer
  • 336,120
  • 22
  • 219
  • 344