当我使用remove(Componet)方法时可以移除组件,但是为什么用removeAll的时候就不行?
import java.util.Scanner;
import javax.swing.JButton;
import javax.swing.JFrame;
public class TestRemove extends JFrame{
JButton jb;
public static void main(String []a)
{
TestRemove tr=new TestRemove();
tr.rem();
}
public TestRemove()
{
jb=new JButton("test");
add(jb);
setSize(300, 300);
setVisible(true);
}
public void rem()
{
Scanner s=new Scanner(System.in);
if(s.nextLine().equals("test"))
{
remove(jb);
//removeAll();
repaint();
}
}
}
------解决方案--------------------
http://tieba.baidu.com/p/2004216123