xdx106200
发贴: 4
积分: 0
|
于 2007-06-27 16:22
原程序如下: import java.awt.*; import java.applet.Applet;
public class Addition extends Applet{ Label prompt; TextField input; int number; int sum;
public void init() { prompt = new Label("请输入整数后回车:"); input = new TextField( 10 ); add( prompt ); add( input ); sum=0; } public boolean action(Event e , Object o) //action 是已过时的API { number = Integer.parseInt( o.toString() ); input.setText ( "" ); // 双引号内不要有空格,否则输入框不是清空,而是留下个空格 sum = sum + number; showStatus( Integer.toString( sum ) ); return true; } }
编译时提示:使用已过时的API,从API手册上查找到提示如下:
public boolean action(Event evt, Object what)已过时。 从 JDK version 1.1 开始,应该将此组件作为组件(激发动作事件)上的 ActionListener 来注册。 如果我要是原程序完善,该这样按API的提示去做,说明白点就是我不知道ActionListener 注册是怎么回事,该怎么操作,或着原程序该怎么改。请高手赐教!
|