<script language="JavaScript">
<!-- Hide script from old browsers
function init(){
// Microsoft Internet Explorer
if (document.all){
document.all.loading.style.visibility="hidden";
document.all.myapplet.style.visibility="visible";
document.applets[0].repaint();
}
// Netscape Navigator
else{
document.loading.visibility="hide";
document.myapplet.visibility="visible";
}
}
// -->
</script>
<BODY onLoad="init()">
<div id="loading" style="position:absolute;left:150;top:10;">
Please wait while Java applet loads...
</div>
<div id="myapplet" style="position:absolute;left:150;top:10;visibility:hidden">
<applet code="charts.charts.class" archive="charts.jar" width="600" height="400" codebase="" VIEWASTEXT>
<Param name="xValue" value="1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,
23,24,25,26,27,28,29,30">
<Param name="yValue" value="22,21,19,23,18,24,28,30,27,22,20,18,16,18,19,16,17,14,12,
13,16,18,19,20,16,17,13,10,14,19,25">
</applet>
</div>
</BODY>
<!-- Hide script from old browsers
function init(){
// Microsoft Internet Explorer
if (document.all){
document.all.loading.style.visibility="hidden";
document.all.myapplet.style.visibility="visible";
document.applets[0].repaint();
}
// Netscape Navigator
else{
document.loading.visibility="hide";
document.myapplet.visibility="visible";
}
}
// -->
</script>
<BODY onLoad="init()">
<div id="loading" style="position:absolute;left:150;top:10;">
Please wait while Java applet loads...
</div>
<div id="myapplet" style="position:absolute;left:150;top:10;visibility:hidden">
<applet code="charts.charts.class" archive="charts.jar" width="600" height="400" codebase="" VIEWASTEXT>
<Param name="xValue" value="1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,
23,24,25,26,27,28,29,30">
<Param name="yValue" value="22,21,19,23,18,24,28,30,27,22,20,18,16,18,19,16,17,14,12,
13,16,18,19,20,16,17,13,10,14,19,25">
</applet>
</div>
</BODY>
用了2个层,第一个层(id为loading)可以写上一些提示消息。而第2个层(id为myapplet)在一开始是不可见的。当applet下载好了,马上把第2个层显示出来,并把第一个层设为不可见。因此,只要这2个层大小,位置必须完全一致。就可以实现我们的目标。
现在我们只差最后一个问题需要解决:如何知道applet已经完全下载了呢?在IE和netscape中都有提供document.all这个属性,当应页面的全部内容(包括applets,图片,声音等)已经下载后该属性为真。好,这样,我们只需监测document.all是否为真,如果是,那就可以把消息所在的层设为不可见,而applet所在的层设为可见,并刷新applet的显示(因为先前applet的显示被隐藏了),否则则相反处理。
引用:
http://www.blogjava.net/Swing/articles/115897.html