Search code examples
javaswingkeylistenerkey-bindingscardlayout

How To Start A JPanel After Switching


I am creating a Pong clone with a menu and the actual game itself. I am using a CardLayout to switch between the two JPanels.

However, when I switch from the menu to the board (or playing area), the board just sits there and won't accept my keyboard inputs. How do I start it or start the key listening?

Source code: https://[email protected]/cg2916/Pong.git


Solution

  • requestFocusInWindow() should do the trick.