import java.awt.*;
import java.awt.event.*;public class sss implements ActionListener
{
Button button=new Button("ok");
TextArea text3=new TextArea(" ",10,10);
TextArea text2=new TextArea(" ",10,10);
TextField text=new TextField(10); public static void main(String args[]) 
{
    sss s = new sss();
    Frame F=new Frame("lihua");
F.setVisible(true);
F.add(s.button);
F.setSize(100,200);
F.add(s.text3,"East");
F.add(s.text2,"Center") ;
F.add(s.text,"West");
F.pack();
s.button.addActionListener(s);//这行出错
}
   public void actionPerformed(ActionEvent e)
{
   text.setText("jj");//这行出错
}
}

解决方案 »

  1.   

    non-static variable this cannot be referenced from a static context,好像和你白天说的一样,不能用在静态函数里!!我想你编译和问题和我这里应该是一样.而text.setText("jj");//这行出错是因为你的text是一个方法变量,你把它设成类变量就没有问题了!TextField text=new TextField(10);提到外面!
      

  2.   

    addActionListener()方法好像不能用静态方法来调用
      

  3.   

    试了 zyg158((DD)One-Time Password System) 的程序,看来我们的理解错了,好好学习!