比如有JTABLE实现的一个面板,还有一个JFRAME框架面板,其中,JFRAME中有一个按钮想通过点击切换到JTABLE面板.不知怎么实现?望高手相助。

解决方案 »

  1.   

    JFRAME.setVisible(false);
    JTABLE.setVisible(true);
      

  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);//下一个
    }
    }楼主可以通过CardLayout布局管理器达到你期望的效果希望对你有帮助