Reputation: 1117
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
Upvotes: 0
Views: 238
Reputation: 1
for CardLayout the listener should have these codes
CardLayout card=(CardLayout) JPanel_with_cardLayout.getLayout();
card.show(JPanel_with_cardLayout,"cardname of card you want to switch");
example:
CardLayout card=(CardLayout) JPanel2.getLayout();
card.show(JPanel2,"card4");
Upvotes: 0
Reputation: 285405
Answer (as recommended to you previously): Don't use a KeyListener. use Key Bindings.
Upvotes: 2