import java.awt.*;public class Frame1 implements ActionListener
{
public static void main(String[] arg)
{
Frame fr = new Frame();
Button bt = new Button("ok");
 bt.addActionListener(this); //这行有错
                  ... }
}出错 提示说 静态的用于非静态  不可以这么写吗 这是怎么回事

解决方案 »

  1.   

    你实现接口ActionListener中的方法了么?
      

  2.   

    implements ActionListener
    实现类的方法 
    public void actionPerformed(ActionEvent e){
    }
      

  3.   

    main是一个static函数,而bt.addActionListener(this)大概是非静态的。
    main在执行的时候,还没有一个该类的实例,所以一般都是先是实例化一个
    Frame1 fr = new Frame1();
    而且参数最好不要用this,而是用实例fr。
      

  4.   

    按以下方法做正确了
    public class Frame1 implements ActionListener
    {
    public static void main(String[] arg)
    {
     Frame1 f = new Frame();
    Frame fr = new Frame();
    Button bt = new Button("ok");
     bt.addActionListener(f); 
                      ...}
    }
      

  5.   

    建议这样:public class Frame1 implements ActionListener
    {
      public static void main(String[] arg)
      {
         Frame1 f = new Frame1();
      }
      public Frame1()
      {
        Button bt = new Button("ok");
        bt.addActionListener(this); 
                      ...
      }
    }
      

  6.   

    问题出在THIS。MAIN是个STATIC,所以不应该出现THIS。 THIS是引用当前对象。