关于cardlayout的问题
package ui;import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class MainFrame extends JFrame implements ActionListener
{
private JPanel card1=new JPanel();
private JPanel card2=new JPanel();
private CardLayout CLayout = new CardLayout();
public MainFrame()
{
addWindowListener(this);
setResizable(false);
setSize(400,300);
setTitle("SalaryMIS");
setLocation(220,170);
setLayout(CLayout);
}
public void setItem()
{
card1.add(Selectbutton);
card2.add(Savebutton);
Selectbutton.addActionListener(this);
add(card1,"卡片1");
add(card2,"卡片2");
}
public void actionPerformed(ActionEvent e)
{
CLayout.show(this,"card2");
}
想作出点击selectbutton 会翻到card2 现在编译能通过 但是运行是点击selectbutton 就会报错
谁帮我看看能如何解决 谢谢