我是初学的,帮我看看??

lhx902 2005-01-04 10:05:30
import java.awt.*;
import java.awt.event.*;

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

}


帮我看看到底是什么问题...
...全文
98 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
classjava 2005-01-04
  • 打赏
  • 举报
回复
建议楼主认真学一下j2se基础
wuxd02 2005-01-04
  • 打赏
  • 举报
回复
试了 zyg158((DD)One-Time Password System) 的程序,看来我们的理解错了,好好学习!
wuxd02 2005-01-04
  • 打赏
  • 举报
回复
addActionListener()方法好像不能用静态方法来调用
wuxd02 2005-01-04
  • 打赏
  • 举报
回复
non-static variable this cannot be referenced from a static context,好像和你白天说的一样,不能用在静态函数里!!我想你编译和问题和我这里应该是一样.而text.setText("jj");//这行出错是因为你的text是一个方法变量,你把它设成类变量就没有问题了!TextField text=new TextField(10);提到外面!
zyg158 2005-01-04
  • 打赏
  • 举报
回复

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");//这行出错
}
}
wuxd02 2005-01-04
  • 打赏
  • 举报
回复
关注..........希望有人回答

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧