下面是我从CardLayoutDemo获取的代码片段。
final static String BUTTONPANEL = "Card with JButtons";
final static String TEXTPANEL = "Card with JTextField";-
//Create the panel that contains the "cards".
cards = new JPanel(new CardLayout());
cards.add(card1, BUTTONPANEL);
cards.add(card2, TEXTPANEL);我不明白上面两个字符串的用法。我假设它们是特定卡的指示符,但是为什么我们不使用下面的代码呢?
//Create the panel that contains the "cards".
cards = new JPanel(new CardLayout());
cards.add(buttonPanel);
cards.add(textPanel);我的意思是,这两个字符串没有任何实际用途,这在我看来很奇怪。
对不起,如果问题含糊不清,请原谅我。
发布于 2015-04-24 01:51:42
String "name“是一个标识符,它允许您指示CardLayout应该显示哪个视图,下面是您在如何使用CardLayout中发布的代码片段.
//Method came from the ItemListener class implementation,
//contains functionality to process the combo box item selecting
public void itemStateChanged(ItemEvent evt) {
CardLayout cl = (CardLayout)(cards.getLayout());
cl.show(cards, (String)evt.getItem());
}https://stackoverflow.com/questions/29837327
复制相似问题