import java.awt.*;
import java.awt.event.*;public class Foo
{
public static void main(String[] args)
    {
     Test t = new Test("匿名类");
     t.setSize(200, 200);
     t.setVisible(true);
    }
}class Test extends Frame
{
private Button button;

public Test(String str)
{
     super(str);
    
     //button = new Button("well");  // 执行OK, 没问题
     //Button button = new Button("well");  // 为什么这句有问题,local variable button is accessed from within inner class; needs to be declared final
     final Button button = new Button("well");  // 为什么声明为 final 类的就能通过
     this.add(button, BorderLayout.NORTH);
     //TestListener handl = new TestListener(this, button);  
     button.addActionListener(new ActionListener(){     
     public void actionPerformed(ActionEvent e)
        {
button.setBackground(Color.red);
button.setLabel("well2");
setBackground(Color.cyan);
    }
    });    
    }
}