如何卸载JPanel面板
先新建一个JPanel类,之后我在主界面的菜单中使用以下代码,替换当前界面的面板,把新的JPanel类做的面板载入.主界面中打开新界面的按钮代码:
public void MaddMan_actionPerformed(ActionEvent actionEvent) {
this.remove(contentPane);
manAdd man = new manAdd();
this.setContentPane(man);
this.show();
}
新的JPanel类的代码如下:
import java.awt.*;
import javax.swing.*;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class Mp
extends JPanel {
public Mp() {
try {
jbInit();
}
catch (Exception exception) {
exception.printStackTrace();
}
}
private void jbInit() throws Exception {
this.setLayout(null);
jButton1.setBounds(new Rectangle(145, 113, 81, 23));
jButton1.setText("jButton1");
jButton1.addActionListener(new Mp_jButton1_actionAdapter(this));
this.add(jButton1);
}
JButton jButton1 = new JButton();
public void jButton1_actionPerformed(ActionEvent e) {
}
}
class Mp_jButton1_actionAdapter
implements ActionListener {
private Mp adaptee;
Mp_jButton1_actionAdapter(Mp adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton1_actionPerformed(e);
}
}
现在问题是,如何卸载这个载入的JPanel类做的面板?回到主界面,具体代码看附件.
untitled2.zip
(19.59 KB)