【发布时间】:2011-07-04 13:50:34
【问题描述】:
Java AWT:清理/删除容器面板
我是 Java AWT 的新手,我想为大学做一个练习。
这将是代码:
public class Panel0 extends JPanel {
//...
private void createMyLayout(bool test) {
this.add(BorderLayout.CENTER, new Panel1(test));
}
//...
}
public class Panel1 extends JPanel {
public Panel1(bool test){
super(new GridLayout(1,4));
if(breed!= Breed.ZOMBIE)
add(new Panel2("helow 1 test"));
else
add(new Panel2("helow 2 test"));
}
}
public class Panel2 extends JPanel{
public Panel2(String myText){
super(new BorderLayout());
add(new JLabel(myText));
}
}
当您调用方法“createMyLayout”时,我需要删除以前的布局并使用新数据重新创建它,但不要完成它。
谢谢。
【问题讨论】: