我找不到CardLayout的JavaDocs。我有一個Applet,從這個Applet我有5個我創建的類擴展JPanel。在這些類中,迄今爲止所做的一切都是設計(一些GUI組件)。現在我想通過Applet將所有這些類連接在一起,以便一次查看一個面板(CardLayout)。因此,我將從我的Applet中使用CardLayout的下一個方法來查看下一個面板。這裏是我的代碼:使用CardLayout將自定義面板添加到Applet
setLayout(new CardLayout());
add(mainView); //mainView, managerView, searchView, storesView and hoursView
add(managerView); // are initialized
add(searchView);
add(storesView);
add(hoursView);
這裏是我的事件處理代碼:
public void actionPerformed(ActionEvent e)
{
CardLayout cl; //CardLayout object to manipulate the next page
cl = (CardLayout)(this.getLayout());
if(e.getSource() == mainView.getManagerButton())
{
cl.next(this);
}
if(e.getSource() == mainView.getSearchButton())
{
cl.next(this); //if the user hits the searchButton I want to link to panel
cl.next(this); // searchView. Is that correct?
}
}
有了這個代碼,我得到一個IllegalArgumentException
有人請指出我的錯誤!我還在代碼中提供了一些關於問題的評論。 一如既往,謝謝!
哪條線顯示了錯誤呢?什麼是確切的錯誤信息?你看過我在另一個問題中鏈接到的CardLayout教程嗎? –