日期:2014-05-20 浏览次数:20761 次
package test;
import java.awt.Button;
import java.awt.Frame;
import java.awt.Panel;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class test extends Frame{
public static void main(String args[]){
test a = new test();
Panel p = new Panel();
a.setSize(200, 400);
a.setVisible(true);
for(int i=0;i<4;i++){
final int fin = i;
Button m = new Button(String.valueOf(i));
m.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
System.out.println(fin);
}
});
p.add(m);
a.add(p);
}
}
public test(){
super();
}
}
final int fin = i;
Button m = new Button(String.valueOf(i));
m.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
System.out.println(fin);
}
});