如何清除一个JFrame?

How to clear a JFrame?

我仍然是 Swing 的菜鸟 类,我想在用户激活按钮后清除屏幕。

    JButton tes=new JButton("TEST");
    tes.setBounds(550, 375, 200, 75);
    tes.setFocusable(false);
    tes.setFont(new Font("comic sans",Font.PLAIN,20));
    tes.setBackground(Color.white);
    tes.setBorder(BorderFactory.createLineBorder(Color.BLACK, 2, true));
    tes.addActionListener(new ActionListener(){
        @Override
        public void actionPerformed(ActionEvent e) {
            try {
                test('T');
            }
            catch(IOException e1) {
                throw new UncheckedIOException(e1);
            }
        }
    });

    f.add(tit);f.add(sub);
    f.add(pr);f.add(tes);
    f.setVisible(true);
}

我已经使用了下面的,但它并没有真正做任何事情。

removeAll()
revalidate();
repaint(); 
private JFrame frame = new JFrame();
frame.getContentPane().removeAll();
frame.repaint();

你应该这样使用它