CardLayout, switch between JPanels by ButtonClick

送分小仙女□ 提交于 2019-12-01 09:28:41

1) The buttons should not be on each panel in the CardLayout. They need to be on another external panel that is always visible, regardless of which card is showing on the card panel.

2) Once your buttons are located correctly, you would add an ActionListener to each, whose actionPerformed method would look something like (using SIM button as an example):

CardLayout cl = (CardLayout) cards.getLayout();
cl.show(cards, "SIM");

Further reading: How To Use CardLayout

EDIT: In theory, you could have the buttons directly on the card panels, but it would be the opposite button on each panel (i.e., the SIM button would be on the Help panel, and vice versa).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!