小弟正在用GUI做一个界面,想要从HomePage切换到InfoCenter界面, 然后从InfoCenter界面切换到InfoCenterFirst界面,这部分已经实现成功,但是从InfoCenterFirst切换回InfoCenter和HomePage时就出错了,请教各位大侠解决方法,谢谢~~
代码如下:HomePage:
import.......public class HomePage extends javax.swing.JFrame {

private InfoCenter ic;
private JDesktopPane jPanel1;
private JITButton jButton1;
private FunctionImp func; public static void main(String[] args) {
final HomePage inst = new HomePage();
SwingUtilities.invokeLater(new Runnable() {
public void run() {
inst.setPreferredSize(new Dimension(805, 605));
inst.setAlwaysOnTop(true); // 总在最前面
inst.setResizable(false);//不改变大小

inst.pack();//调整此窗口的大小,以适合其子组件的首选大小和布局
inst.setVisible(true);
inst.setLocationRelativeTo(null);
}
});
inst.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
if(ConnectionTunnelValue.getTunnel()!=null){
try {
ConnectionTunnelValue.getTunnel().disconnect("");
} catch (EICLException e1) {
e1.printStackTrace();
}
}
System.exit(1);
}
});
}

public void set(){
...
}
public HomePage() {
super();
set();
initGUI();
func = new FunctionImp();
}

private void initGUI() {
try {
{
jPanel1 = new JDesktopPane();
getContentPane().add(jPanel1, BorderLayout.CENTER);
ic = new InfoCenter(this,jPanel1);
jPanel1.setLayout(null);
jPanel1.setPreferredSize(new java.awt.Dimension(336, 234));
{
jButton1 = new JITButton();
jPanel1.add(getJButton1());
jButton1.setOpaque(false);
jButton1.setText("信息中心");
jButton1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
setContentPane(ic);
}
});
       }

}
pack();
this.setSize(420, 371);
} catch (Exception e) {
e.printStackTrace();
}
}}
InfoCenter:
import .....;public class InfoCenter extends javax.swing.JDesktopPane {
private JITButton jButton1;
private JFrame mf;
private JDesktopPane lastPanel;
private InfoCenterFirst icFirst;
private FunctionImp func;

public InfoCenter(JFrame mf, JDesktopPane lastPanel) {
super();
initGUI();
this.mf = mf;
this.lastPanel = lastPanel;
func = new FunctionImp();
}
private void initGUI() {
try {

icFirst = new InfoCenterFirst(mf, lastPanel);
this.setBackground(new java.awt.Color(51,51,51));
this.setSize(805,605);
{
jButton1 = new JITButton();
this.add(jButton1);
jButton1.setText("一层");
jButton1.setOpaque(false);
jButton1.setIcon(new ImageIcon(getClass().getClassLoader().getResource("res/ButtonIcon.png")));
jButton1.setBounds(30, 315, 73, 33);
jButton1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
mf.setContentPane(icFirst);
}
});
}
} catch (Exception e) {
e.printStackTrace();
}
}
public JLabel getJLabel2() {
return jLabel2;
}}
InfoCenterFirst:
import ......public class InfoCenterFirst extends javax.swing.JDesktopPane {
private JITButton jButton3;
        private JITButton jButton6;
private JFrame mf;
private JDesktopPane lastPanel;
private InfoCenter infoCenter;
private FunctionImp func;

public InfoCenterFirst(JFrame mf, JDesktopPane lastPanel) {
super();
initGUI();
this.mf = mf;
this.lastPanel = lastPanel;
func = new FunctionImp();
}
private void initGUI() {
try {
this.setBackground(new java.awt.Color(51,51,51));
this.setSize(805,605);
{
jButton3 = new JITButton();
this.add(jButton3);
jButton3.setText("主界面 HOMEPAGE");
jButton3.setOpaque(false);
jButton3.setIcon(new ImageIcon(getClass().getClassLoader().getResource("res/ButtonIcon.png")));
jButton3.setBounds(513, 476, 127, 35);
jButton3.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
mf.setContentPane(lastPanel);
}
});
}
{
jButton6 = new JITButton();
this.add(jButton6);
jButton6.setText("信息中心");
jButton6.setOpaque(false);
jButton6.setIcon(new ImageIcon(getClass().getClassLoader().getResource("res/ButtonIcon.png")));
jButton6.setBounds(161, 476, 134, 33);
jButton6.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
mf.setContentPane(infoCenter);
}
});
}
} catch (Exception e) {
e.printStackTrace();
}
}
public JLabel getJLabel2() {
return jLabel2;
}}