求高手指点,注册监视器了怎么JButton没反应?
import java.awt.Container;import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
/*
* 在窗口有一个按钮点击这个按钮,按钮的点击次数会显示在这按钮上
* */
public class Teste_5 {
static Action a;
public static void main(String[] args) {
a=new Action();
}
}
class Action implements ActionListener{
JFrame f;
JButton butt1;
int i=0;
Action(){
JFrame f=new JFrame();
JButton butt1=new JButton("i");
f.setSize(400, 500);
f.setLayout(new FlowLayout());
Container con=f.getContentPane();
con.add(butt1);
butt1.addActionListener(this);
f.setVisible(true);
}
public void actionPerformed(ActionEvent e){
if(e.getSource()==butt1){
int n=Integer.parseInt(butt1.getText());
n++;
butt1.setText(String.valueOf(n));
}
}
}