JAVA在JFrame中添加按钮,如果点击这个按钮,就清除这个按钮,怎么实现啊?

JAVA在JFrame中添加按钮,如果点击这个按钮,就清除这个按钮,怎么实现啊?用remove方法,,但点完后按钮颜色不恢复,,按钮也不消失。

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class r extends JFrame implements ActionListener
{
public static void main(String[] args)
{
new r();
}
r()
{
r.b=new JButton("点我试试");
r.b.addActionListener(this);
add(r.b);
setSize(300,200);
setLocationRelativeTo(null);
pack();
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void actionPerformed(ActionEvent e)
{
remove(r.b);
repaint();
}
static JButton b;
}
温馨提示:答案为网友推荐,仅供参考
第1个回答  2017-06-21
SwingUtilities.updateComponentTreeUI(this);
相似回答