为什么Applet程序在JCreator中和用IE执行时的效果不一样?
就是这个程序: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);
}
}
在JCreator中运行后,将窗口不断最小化再恢复可以看到 initCounter,startCounter,stopCounter,destroyCounter 的变化,但是用IE却看不到这种效果,数值始终不变,这是怎么原因?
[此贴子已经被作者于2006-2-24 7:10:41编辑过]
----------------解决方案--------------------------------------------------------
怎么打开Java控制台?
----------------解决方案--------------------------------------------------------
没人知道吗,难过。。
----------------解决方案--------------------------------------------------------
以下是引用Grace_TT在2006-2-24 7:10:00的发言:
就是这个程序:
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);
}
}
在JCreator中运行后,将窗口不断最小化再恢复可以看到 initCounter,startCounter,stopCounter,destroyCounter 的变化,但是用IE却看不到这种效果,数值始终不变,这是怎么原因?
就是这个程序:
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);
}
}
在JCreator中运行后,将窗口不断最小化再恢复可以看到 initCounter,startCounter,stopCounter,destroyCounter 的变化,但是用IE却看不到这种效果,数值始终不变,这是怎么原因?
这是因为JCreator中运行的时候,它是启动了appletviewer,而在IE中,你每次动作,它都不会repaint自己,所以你每次最小化看不出什么东西,即使你刷新一次也看不出,因为刷新的时候这个applet又被重新装载了一次,那么它成员变量又回到了刚初始化的样子了。
----------------解决方案--------------------------------------------------------
那为什么下面的这个程序在JCreactor和IE中的执行结果是一样的呢:
import java.applet.*;
import java.awt.*;
public class Parameters extends Applet
{
private String toDisplay;
private int speed;
private int distance;
public void init()
{
String pv;
pv=getParameter("Speed");
String ps;
ps=getParameter("Distance");
if(pv==null&&ps==null)
{
speed=10;
distance=100;
}
else
{
speed=Integer.parseInt(pv);
distance=Integer.parseInt(ps);
}
toDisplay="Speed Parameter:"+speed;
}
public void paint(Graphics g)
{ Parameters a=new Parameters();
g.drawString(toDisplay,25,25);
toDisplay="Distance Parameter:"+distance;
g.drawString(toDisplay,25,35);
}
}
第一次的结果是:Speed Parameter:12
Distance Parameter:500
最小化再还原:Distance Parameter:500
Distance Parameter:500
这是什么原因呢?
----------------解决方案--------------------------------------------------------