改成这样:Test.this.setBackground(Color.cyan);

解决方案 »

  1.   

    为什么不能加this呢? 
    在匿名类中的默认this是谁?
    不是button, 不是Test, 是谁.
      

  2.   

    是new ActionListener这个对象。
      

  3.   

    在一个类当中使用this都是指这个类的实例本身,无论它是不是内部类
    所以this.setBackground表示的是new ActionListener()这个内部匿名类的方法setBackgroundTest.this.setBackground指的就是当前拥有这个内部类的父类实例本身的方法
      

  4.   

    匿名类也是类,这里的this是指你的new ActionListener(),也就是匿名类本身听我的,没错的