简体   繁体   English

获取按钮以切换卡

[英]Getting a button to switch cards

I have a log in GUI that when i click a button, it gets text from the username and password, and if it is correct, it moves on to a new panel. 我有一个登录GUI,当我单击一个按钮时,它会从用户名和密码中获取文本,如果正确,它将移至新面板。 i have the panel called optionPanel and i want the button to go to it specifically. 我有一个名为optionPanel的面板,我希望按钮专门转到该面板。 all of the panels are set up as cards, so i can switch between them smoothly. 所有面板都设置为卡,因此我可以在它们之间平滑切换。 I know how to make the button move to the next panel/card in the sequence, but i don't know how to make it go to the panel/card called optionPanel . 我知道如何使按钮按顺序移动到下一个面板/卡,但是我不知道如何使按钮转到名为optionPanel的面板/卡。

EDIT: I dont know if im being very clear, but in my head, this makes perfect sense. 编辑:我不知道我是否很清楚,但是在我看来,这很合理。 please tell me how i can be more clear so i can get an answer. 请告诉我如何变得更加清晰,这样我才能得到答案。 THANKS 谢谢

don't you just need 你不是只需要

cardLayout.show(cards, "optionPanel");

or am i missing something completely non-obvious? 还是我错过了一些完全不明显的东西?

I think what you want is: 我认为您想要的是:

// Create the panels
JPanel loginPanel = new JPanel();
JPanel someOtherPanel1 = new JPanel();
JPanel someOtherPanel2 = new JPanel();
JPanel optionPanel = new JPanel();
JPanel someOtherPanel3 = new JPanel();

// Add them to a card layout
JPanel cards = new JPanel(new CardLayout());
cards.add(loginPanel, "loginPanel");
cards.add(someOtherPanel1, "someOtherPanel1");
cards.add(someOtherPanel2, "someOtherPanel2");
cards.add(optionPanel, "optionPanel");
cards.add(someOtherPanel3, "someOtherPanel3");

...

// Switch to the optionPanel
cards.getLayout().show(cards, "optionPanel");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM