在这个小程序中,我想测试一下init(),start(),stop(),destroy()这几个方法,但是
但是由于在点击X后,小程序窗口随之关闭,调用destroy()的结果看不到,我想在程序中通过System.out.prinln()把destroyCounter的结果显示出来,但是程序运行错误,是什么问题呢?我这种方法是否可行,如果可行要怎么改,如果不行,有没有什么其它的方法能够看到destroyCounter的结果。程序如下:
import java.awt.*;
import java.applet.*;
public class appletLifeCircle extends Applet
{
int initCounter=0;
int startCounter=0;
int stopCounter=0;
int destroyCounter=0;
public void init()
{
initCounter++;
}
public void start()
{
startCounter++;
}
public void stop()
{
stopCounter++;
}
public void destroy()
{
destroyCounter++;
}
public void paint(Graphics g)
{
g.drawString("init has been invoked"+String.valueOf(initCounter)+" times ",20,20);
g.drawString("start has been invoked"+String.valueOf(startCounter)+" times ",20,30);
g.drawString("stop has been invoked"+String.valueOf(stopCounter)+" times ",20,40);
g.drawString("destroy has been invoked"+String.valueOf(destroyCounter)+" times ",20,50);
}
appletLifeCircle a =new appletLifeCircle();//因为看不到调用destroy()的结果,我加了
System.out.println(a.destroy()); //这两句,但是出错了。
}
谢谢各位!
[此贴子已经被作者于2006-2-21 14:23:17编辑过]