作如下的修改,我已经测试过了。
        menuItem1.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent e)
            {
                cp.removeAll();
                cp.add(p1);
                    cp.validate();
                    cp.repaint();//增加repaint()方法既可。
            }
        });
        menuItem2.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent e)
            {
                cp.removeAll();
                cp.add(p2);
                    cp.validate();
                    cp.repaint();//增加repaint()方法既可。
            }
        });

解决方案 »

  1.   

    menuItem1.addActionListener(new ActionListener(){
                public void actionPerformed(ActionEvent e)
                {
                    cp.removeAll();
                    cp.add(p1);
                        cp.validate();
                        cp.repaint();//增加repaint()方法既可。
                }
            });
            menuItem2.addActionListener(new ActionListener(){
                public void actionPerformed(ActionEvent e)
                {
                    cp.removeAll();
                    cp.add(p2);
                        cp.validate();
                        cp.repaint();//增加repaint()方法既可。
                }
            });