一个小问题,帮帮小弟
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class HideButton extends JFrame implements ActionListener
{
private JButton jbutton;
private Container c;
public HideButton()
{
JButton jbutton = new JButton("隐藏按钮");
c = getContentPane();
c.setLayout(new FlowLayout(FlowLayout.CENTER));
c.add(jbutton);
jbutton.addActionListener(this);
setSize(300,200);
show();
}
public void actionPerformed(ActionEvent e)
{
//((JButton)e.getSource()).setVisible(false);//正常
jbutton.setVisible(false); //运行出错
}
public static void main(String[] args)
{
HideButton app = new HideButton();
}
}
为什么不可以直接用jbutton.setVisible(false);