求救!组件或容器的remove()或removeAll()怎么用
谁帮我看看,以下代码怎么才能把面板上的按钮移除掉。
//Test.java
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
public class Test extends JFrame{
JButton b1;
public Test(){
Container contentPane = getContentPane();
contentPane.setLayout(null);
b1 = new JButton("one");
contentPane.add(b1);
Insets insets = contentPane.getInsets();
b1.setBounds(35 + insets.left, 15 + insets.top, 75, 20);
contentPane.addMouseListener(
new MouseAdapter(){
public void mousePressed(MouseEvent e){
removeAll();
}
}
);
}
public static void main(String[] args){
Test t=new Test();
t.setSize(200,200);
t.setVisible(true);
}
}