requestFocus() not working with show() method
I'm making a game where the program has to show one panel, and from that panel show the previous panel, and then show the first panel again. To make things simpler, let's say we have PanelA and PanelB in a CardLayout c of panelc. The program starts with c.show(panelc, "PanelB"); panelb.requestFocus();. Then, in PanelB, this happens: c.show(panelc, "PanelA"). Then, in PanelA, the same thing happens again: c.show(panelc, "PanelB"); panelb.requestFocus();
The first time around, the requestFocus() works perfectly with my KeyListener and the game works fine. But the second time around when panelb is shown, it seems the requestFocus does not work and KeyListener does not respond to any events.