请问如何在多个面板间使用CardLayout布局管理器呢?如能给代码,大谢.

解决方案 »

  1.   

    south.add("content",content_in_south);
    south.add("perform",perform_in_south);//上面的语句是添加两个面版到south中去,
             //下面是响应事件
              if(evt.target instanceof Component &&
       ((Component)evt.target).getParent().equals())
      

  2.   

    import java.awt.*;
    import java.awt.event.*;public class exec 
    {
    public static void main(String args[])
    {
    MyFrame m=new MyFrame("OK");
    m.setSize(200,400);
    m.setVisible(true);
    }
    }class MyFrame extends Frame implements ActionListener
    {
    CardLayout c=new CardLayout();
    Label l1=new Label("Label1");
    Label l2=new Label("Label2");
    Label l3=new Label("Label3"); Button b1=new Button("<-");
    Button b2=new Button("->"); Panel p1=new Panel();
    Panel p2=new Panel();
    public MyFrame(String title)
    {
    super(title);
    setLayout(new FlowLayout(FlowLayout.CENTER,0,0));
    p1.setLayout(c);
    l1.setBackground(Color.red);
    l2.setBackground(Color.green);
    l3.setBackground(Color.blue);
    p1.add("a",l1);//用“1”,“one”皆可
    p1.add("b",l2);
    p1.add("c",l3);
    add(p1);
    p2.setLayout(new FlowLayout(FlowLayout.CENTER,0,50));
    p2.add(b1);
    p2.add(b2);
    add(p2);

    b1.addActionListener(this);
    b2.addActionListener(this);
    }
    public void actionPerformed(ActionEvent e)
    {
    Graphics g=getGraphics();
    if(e.getSource()==b1)c.previous(p1);//上一个
    if(e.getSource()==b2)c.next(p1);//下一个
    }
    }楼主
    希望对你有帮助
      

  3.   

    谢谢hujiaboy啦。
    看了你的东西,感到很受益。