我在Panel1中放置了4个按钮,每点击一个按钮,对应出现这个按钮的panel,(只做了一个面板试验),
eg:当我点击regester按钮,RegesterPanel就会出现在BorderLayout.center,用e.getSource()==regester事件,可是抛出异常,哪位高手能帮我把程序改进一下,感激不尽.
public class Account extends JApplet{
Panel1 p1; Panel2 p2;
public void init(){
setSize(400,200);
p1=new Panel1();
p2=new Panel2();
setLayout(new BorderLayout());
add(p1,BorderLayout.NORTH);
add(p2,BorderLayout.CENTER);
}
}
class Panel1 extends JPanel implements ActionListener{
JButton regester,save,withdraw,show;

public Panel1(){
setLayout(new FlowLayout());
setBackground(Color.pink);
regester=new JButton("Regester");
regester.addActionListener(this);
save=new JButton("SaveMoney");
save.addActionListener(this);
withdraw=new JButton("Withdraw");
withdraw.addActionListener(this);
show=new JButton("Check");
show.addActionListener(this);
add(regester); add(save); 
add(withdraw); add(show);

}
public void actionPerformed(ActionEvent e) {
Panel2 p=null;
if(e.getSource()==regester){
p.card.show(regester, "Regester");
}
else if(e.getSource()==save){

}
else if(e.getSource()==withdraw){

}
else if(e.getSource()==show){

}
}
}
class Panel2 extends JPanel{
CardLayout card=null;
JPanel p=null;
RegesterPanel regester;
public Panel2(){
p=new JPanel();
regester=new RegesterPanel();
card=new CardLayout();
setLayout(card);
add("JPanel",p);
add("Regester",regester);
}
}
class RegesterPanel extends JPanel implements ActionListener{
JLabel label1,label2,label3,label4;
JTextField text1,text2,text3;
Box baseBox,boxV1,boxV2;
JButton button;
public RegesterPanel(){
label1=new JLabel("请输入您的姓名");
label2=new JLabel("请输入您的地址");
label3=new JLabel("请输入开户金额");
label4=new JLabel("点击确认");
text1=new JTextField(15);
text2=new JTextField(15);
text3=new JTextField(15);
button=new JButton("确认");
boxV1=Box.createVerticalBox();
boxV1.add(label1);
boxV1.add(Box.createVerticalStrut(14));
boxV1.add(label2);
boxV1.add(Box.createVerticalStrut(12));
boxV1.add(label3);
boxV1.add(Box.createVerticalStrut(12));
boxV1.add(label4);
boxV2=Box.createVerticalBox();
boxV2.add(Box.createVerticalStrut(10));
boxV2.add(text1);
boxV2.add(Box.createVerticalStrut(8));
boxV2.add(text2);
boxV2.add(Box.createVerticalStrut(8));
boxV2.add(text3);
boxV2.add(Box.createVerticalStrut(8));
boxV2.add(button);
baseBox=Box.createHorizontalBox();
baseBox.add(boxV1);
baseBox.add(Box.createHorizontalStrut(15));
baseBox.add(boxV2);
add(baseBox);
}
public void actionPerformed(ActionEvent e) {

}
}