wrong parent for cardlayout?????
import javax.swing.*;import java.awt.*;
import java.awt.event.*;
public class testCard
{
public static void main(String [] args)
{
demo_8 test=new demo_8();
}
}
class demo_8 extends JFrame
{
JPanel jp;//最底部的面板
JPanel jpNorth;//放置card的面板
JPanel jpButton;//放置按钮的面板
JPanel jp1;
JPanel jp2;
JPanel jp3;
JPanel jp4;
JPanel jp5;
JButton jb1;
JButton jb2;
CardLayout card=new CardLayout();
public demo_8()
{
jp=new JPanel();
jpButton=new JPanel();
this.setBounds(0,0,400,300);
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setContentPane(jp);
jpNorth=new JPanel();
jp.add(jpNorth,BorderLayout.CENTER);
jpNorth.setLayout(card);
jp1=new JPanel();
jp2=new JPanel();
jp3=new JPanel();
jp4=new JPanel();
jp5=new JPanel();
jb1=new JButton("jb1");
jb2=new JButton("jb2");
jp.add(jpButton,BorderLayout.SOUTH);
jpButton.add(jb1);
jpButton.add(jb2);
card.addLayoutComponent(jp1,"jp1");
card.addLayoutComponent(jp2,"jp2");
card.addLayoutComponent(jp3,"jp3");
card.addLayoutComponent(jp4,"jp4");
jb1.addActionListener
(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
card.previous(jp2);
}
}
);
jb2.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
card.next(jp1);
}
}
);
}
}
报错图: