这是以前做的一个小东西,里面的 MainFace.java 大概跟您说地差不多
你可以参考一下思路何实现方法。  (献丑了)
===============================================================
/**
 *   [MainFace.java]    主体面板布局类
 * 
 * 创建日期:(2003-8-2)
 * @author:ONE_Fox
 */
 
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;public class MainFace extends JFrame {
    
    //操作面板---------------------//
    private JPanel searchFace = null;
    private JPanel addFace = null;
    private JPanel countFace = null;
    
    //界面组件---------------------//
    private JRadioButton search = new JRadioButton("查询", true);
    private JRadioButton add = new JRadioButton("添加");
    private JRadioButton count = new JRadioButton("统计");
    private ButtonGroup BTGroup = new ButtonGroup();    private Container contentPane = this.getContentPane();
/**
* 构造方法:
* @param searchFace JPanel  搜索面板
* @param addFace JPanel  添加面板
* @param countFace JPanel  统计面板
*/  
    public MainFace(JPanel searchFace, JPanel addFace, JPanel countFace) {
        this.searchFace = searchFace;
        this.addFace = addFace;
        this.countFace = countFace;
        
        //界面制作------------------------//
        makeFace();
        addListener();
    }
/**
* 方法:面板构建
*/  
    private void makeFace() {
        BTGroup.add(search);
        BTGroup.add(add);
        BTGroup.add(count);        JPanel upPanel = new JPanel();
        upPanel.setLayout(new FlowLayout(FlowLayout.CENTER, 15, 3));
        upPanel.add(search);
        upPanel.add(add);
        upPanel.add(count);        //总体布局----------------------//
        contentPane.add(upPanel, BorderLayout.NORTH);
        contentPane.add(searchFace, BorderLayout.CENTER);
    }
    
    
/**
* 方法:面板显示
*/  
    public void showFace() {
        this.setTitle("房改房资料管理系统");
        setSize(550,350);
        Dimension dime = Toolkit.getDefaultToolkit().getScreenSize();
        setLocation(dime.width/2 - 275, dime.height/2 - 175);
        setResizable(false);
        show();
    }
    /**
* 方法:事件监听
*/  
    private void addListener() {
        
        //添加窗口关闭事件------------------//
        this.addWindowListener(new WindowAdapter(){
            public void windowClosing(WindowEvent e){
                if(dbload.Loader.getLoader().disconnect()) {
                    dispose();
                    System.exit(0);
                }
                else {
                    dispose();
                    System.exit(1);
                }
            }
        });
        
        //"查询" 按钮----------------------//
        search.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent e){
                contentPane.remove(addFace);
                contentPane.remove(countFace);
                contentPane.add(searchFace, BorderLayout.CENTER);
                contentPane.repaint();
                show();
            }
        });
        
        //"添加" 按钮---------------------//
        add.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent e){
                contentPane.remove(searchFace);
                contentPane.remove(countFace);
                contentPane.add(addFace, BorderLayout.CENTER);
                contentPane.repaint();
                show();
            }
        });
        
        //"统计" 按钮---------------------//
        count.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent e){
                contentPane.remove(searchFace);
                contentPane.remove(addFace);
                contentPane.add(countFace, BorderLayout.CENTER);
                contentPane.repaint();
                show();
            }
        });
    }
}

解决方案 »

  1.   

    onefox(一品狐) :谢谢你的代码,得到了一些启示
    但是如果我需要切换的面板很多,是不是也要用remove来切换?
      

  2.   

    remove 是把当前面板上的某组件移除掉,然后你可以再add进需要显示的新组件再 repaint()然后 show() 一下
    =============================
    我不保证上面的做法是最好的, 
    但是我试过这样的流程再替换显示界面时不会有闪烁
      

  3.   

    现在我实在用jb做,请问每一个面板可不可以独立出来利用jb做,还是需要自己编写?
      

  4.   

    我一直都是手写界面的, 反正用 java 做的界面一般不会很复杂自己写的界面思路很清晰上面的例子里3个替换显示的面板都是 JPanelJB 我装完 3 分钟就删了,用它做界面一塌糊涂(可能我比较笨吧)