Applet Demo smooth download and splash (Updated 2007-12-13) : New version

This is a generic AppletLoader (javascript) Works with all Applet and SUN+MS JVM

No Java splash, no computer freez (not a long one ;-)) , and finally no click to activate control.

http://demo.dzzd.net/JScripts/
http://demo.dzzd.net/JScripts/index2.htm

please let comments and bugs on your platforms as the following:
FF 1.5 Windows XP (SUN1.6) => Ok
FF 2.0 Windows XP (SUN1.6) => Ok
IE 1.6 Windows XP (MS1.1+SUN1.6) => Ok

Need to polish source code a little before releasing

UPDATE:
a different layout with same applets using a single target window http://demo.dzzd.net/JScripts/index2.htm

UPDATE:

A first source code, it may be improved but this is the one currently used. you can view html source code of the above url to see how to use it

UPDATE:
Source code updated (I introduced a MSJVM bugs while trying to resolve a bug appening in safari browser), it is now resolved new version works with MSJVM

UPDATE:
Source code updated, add message when unable to start applet also ask the user to install java if unable to detect any JVM

UPDATE:
Source code updated, now works on Safari 3.0.4 windows XP

UPDATE:
Better Jar and classe file cache enable fast switch between applet once an applet have been loaded it can be started immediatly

UPDATE:
Java script refound from scratch


  /**
       * 3DzzDAppletScript.js
       *
       * This source code is a part of 3DzzD Web 3D engine you may use it as long as you provide the orignal source author and website and this comment unmodified
       *
       * @author bruno augier
       * @email bruno.augier@dzzd.net
       * @website http://dzzd.net/
       * @version 1.00 2007/12/03
  */
  
  var jvmInited=false;
  var imageLoad=new Image();
  imageLoad.src="INIT.GIF";
  var preloadingJar = new Array();
  
  function loadApplet(targetAppletId,appletName,appletTag,width,height,preloadJarFiles)
  {
    if(document.getElementById(appletName))
		return;	
    
    var msg="Loading Applet "+ appletName;
    window.status=msg;
	var target=document.getElementById(targetAppletId);
	var html="";
    html+="<TABLE ID=\""+targetAppletId+"LOADER\" cellSpacing=0 cellPadding=0 WIDTH=\""+width+"\" HEIGHT=\""+height+"\" STYLE=\"border:0\" >";
    html+="<TR><TD vAlign=\"center\" align=\"middle\">";
	html+="<IMG ";
    html+=" ALT=\""+ msg + "\" ";
    html+=" SRC=\"INIT.GIF\" ";
    html+=" >";
    html+="</TD></TR></TABLE><DIV STYLE=\"visibility:hidden\" ID=\""+targetAppletId+"APPLET\"></DIV>";	
	target.innerHTML=html;
	var nbApplet=document.applets.length;
	
	if(preloadJarFiles!=null && preloadJarFiles.replace(" ","")!="")
	{
		preloadJars(preloadJarFiles);
		setTimeout("showAppletOnceStartedPreload(\""+targetAppletId+"\",\""+appletName+"\",\""+appletTag+"\",\""+width+"\",\""+height+"\",\""+preloadJarFiles+"\","+nbApplet+")",100);
	}
	else
	{
		setTimeout("showAppletOnceStarted(\""+targetAppletId+"\",\""+appletName+"\",\""+appletTag+"\",\""+width+"\",\""+height+"\","+nbApplet+")",100);
	}	
  }
  
  function showAppletOnceStartedPreload(targetAppletId,appletName,appletTag,width,height,preloadJarFiles,nbApplet)
  {
	if(!isJarsPreloaded(preloadJarFiles))
		setTimeout("showAppletOnceStartedPreload(\""+targetAppletId+"\",\""+appletName+"\",\""+appletTag+"\",\""+width+"\",\""+height+"\",\""+preloadJarFiles+"\","+nbApplet+")",1250);
	else
		setTimeout("showAppletOnceStarted(\""+targetAppletId+"\",\""+appletName+"\",\""+appletTag+"\",\""+width+"\",\""+height+"\","+nbApplet+")",250);
  }
  
  function showAppletOnceStarted(targetAppletId,appletName,appletTag,width,height,nbApplet)
  {
    var target=document.getElementById(targetAppletId+"APPLET");
	
	if(target.innerHTML.toUpperCase().indexOf("<APPLET ")==-1)
	{
		target.innerHTML+=appletTag;
		setTimeout("showAppletOnceStarted(\""+targetAppletId+"\",\""+appletName+"\",\""+appletTag+"\",\""+width+"\",\""+height+"\","+nbApplet+")",250);
		return;
	}
	
    if(jvmInited)
	{
		if(document.applets.length>nbApplet)
		{
		    var applet=document.getElementById(appletName);
			if(applet!=null)
			{
				if(document.applets[appletName])
				{
					var msg="Applet loaded and started " + appletName;
					window.status=msg;
					setTimeout("showApplet(\""+targetAppletId+"\",\""+appletName+"\",\""+width+"\",\""+height+"\")",250);
					return;
				}  
			}
		}
	}
	setTimeout("showAppletOnceStarted(\""+targetAppletId+"\",\""+appletName+"\",\""+appletTag+"\",\""+width+"\",\""+height+"\","+nbApplet+")",250);
  }
  
  function showApplet(targetAppletId,appletName,width,height)
  {
	var applet=document.getElementById(appletName);
	var loader=document.getElementById(targetAppletId+"LOADER");
  	loader.style.display="none";
	applet.width=width;
	applet.height=height;
	applet.style.width=width;
	applet.style.height=height;
	var target=document.getElementById(targetAppletId+"APPLET");
	target.style.visibility="visible";
  }
    
  function preloadJars(files)
  {
	var fileArray=files.replace(";",",").split(",");
	for(var c=0;c<fileArray.length;c++)
	{
	 preloadJar(fileArray[c]);	
	}  
  }

  
  function isJarsPreloaded(files)
  {
	var fileArray=files.replace(";",",").split(",");
	for(var c=0;c<fileArray.length;c++)
	{
		if(!fileArray[c])
			return false;
	}
	return true;
  }

  function isJarPreloaded(name)
  {
	if(preloadingJar[name]==null)
		return false;
		
	return preloadingJar[name];	
  }
  
  function preloadJar(name)
  {
	   
	   if(preloadingJar[name])
		return;
       preloadingJar[name]=false;
       var f=window.frames[name];
       if(!f)
       {
            document.body.innerHTML+="<IFRAME NAME=\""+name+"\" WIDTH=0 HEIGHT=0 STYLE=\"border:0\"></IFRAME>";
            f=window.frames[name];
            f.document.open("text/html");
            var iframeHTML="";
            iframeHTML+="<HTML><BODY onload=\"parent.preloadingJar['"+name+"']=true;\" SCROLL=NO STYLE=\"margin:0\" >";
            iframeHTML+="<APPLET ARCHIVE=\""+name+"\" NAME=\""+name+"\" WIDTH=0 HEIGHT=0 ";
            iframeHTML+=" CODE = \"java.applet.Applet\" ";
            iframeHTML+="</APPLET>";
            iframeHTML+="</BODY></HTML>";
            f.document.write(iframeHTML);
            f.document.close();
       }
  }
  var initJVMCount=0;
  /**
       * Initialise Java JVM, this may hang few seconds
  */
  function loadJVM()
  {
       if(jvmInited)
       return;
       if(initJVMCount>15)
       {
            if(confirm("Java Plugin requiered, do you want to instal Java Plugin ?"))
            window.location.href="http://java.com/";
            jvmInited=true;
            return;
       }
       var f=window.frames["JVMLOADER"];
       if(!f)
       {
            document.body.innerHTML+="<IFRAME NAME=\"JVMLOADER\" WIDTH=0 HEIGHT=0 STYLE=\"border:0\"></IFRAME>";
            f=window.frames["JVMLOADER"];
            f.document.open("text/html");
            var iframeHTML="";
            iframeHTML+="<HTML><BODY SCROLL=NO STYLE=\"margin:0\" >";
            iframeHTML+="<APPLET WIDTH=0 HEIGHT=0 ";
            iframeHTML+=" CODE = \"java.applet.Applet\" ";
            iframeHTML+="</APPLET>";
            iframeHTML+="</BODY></HTML>";
            f.document.write(iframeHTML);
            f.document.close();
       }
       if(f.document.applets.length==0)
       {
            setTimeout("loadJVM()",2000);
            initJVMCount++;
            return;
       }
	   
       // Workaround for Safari 3.0.4 embeded code crash windows XP with safari ?!
       if(navigator.userAgent.toUpperCase().indexOf("SAFARI")==-1)
       {
            try
            {
                 if(!f.document.applets[0].isActive())
                 {
                      setTimeout("loadJVM()",500);
                      initJVMCount++;
                      return;
                 }
            }
            catch(e)
            {
                 setTimeout("loadJVM()",500);
                 initJVMCount++;
                 return;
            }
       }
       jvmInited=true;
       f.document.open("text/html");
       var iframeHTML="";
       iframeHTML+="<HTML><BODY SCROLL=NO STYLE=\"margin:0\" >";
       iframeHTML+="</BODY></HTML>";
       f.document.write(iframeHTML);
       f.document.close();
  }
 

XP SP2 / Opera 9.22 / Sun 1.6: works.

XP SP2, Opera 9.5 beta - works. Cool stuff.

Very nice.

Works on IE7 on Windows XP SP2 with SUN JRE 1.6

An other layout, same applets but only one display window

http://demo.dzzd.net/JScripts/index2.htm

Looks good in IE, Firefox.

No go on Safari: TypeError: Undefined value (http://demo.dzzd.net/JScripts/3DzzDAppletScript.js line 136)

On Firefox it looks like it might have the same “white flash” issue that the pulpcore.js loader has (it’s obvious if the page background is black). I’ve been trying to find a workaround, but haven’t found one yet.

Very nice <2sec. freeze on ff 2.0 first load and instant thereafter.
IE6 got some repaint problem when I clicked “Click to start applet 1” (after the initial load and before the spinning loading image).Problem gone second time around.

Win XP, Java 1.6

Just about as good as the milpa loader and way better than the normal loader. Wish something like that this would be a part of the normal java applet.
So it looks like this could be a generic “wrapper” around any applet. What Java versions does it support?

Nice particle effects as well :slight_smile:

Hum i have done some improvments if possible please give it another try with safari as now the line number is no more valid :-(, also I will add a “fallback” if any problem happen in loading applet it will first be loaded old way but still at the right pos and if it doesn’t works it will be opened in a popup in a way even more older without dynamic html inside.

hum doesn’t come from applet itself ? dont really see what you mean could you give me more info ?

PS: I also add a fourth applet

[quote]What Java versions does it support?
[/quote]
all JVM version including Microsoft JVM,

It is full JavaScript and does not requiere applet modifications (the only requierment is that applet dont crash with a width and height equals to zero and take care of resizing)

Same issue, still on line 136. In Safari it just says on the loading pacifier. Happens in both Mac and Windows versions of Safari.

As for the Firefox “white flash” issue, i’ve been this on Windows. It is more obvious If your page is black and your applet is painted black. You will see a “white flash” where the applet is a split-second before Firefox shows the applet. It doesn’t always happen on my machine - about 1 out of 5 times - so you have to reload a bunch of times to see it. I found a workaround for pulpcore.js but it inserts a 1-second delay before showing the applet, and I want to try to avoid that extra delay.

Works great here. Good job.

[quote]Same issue, still on line 136. In Safari it just says on the loading pacifier. Happens in both Mac and Windows versions of Safari
[/quote]
I tried a fix, you may give it another try , hop it will works this time… :-\

This stuff doesn’t really fix anything. It still hangs, its not even a loader.
Don’t get me wrong, I appreciate your efforts, but showing an animated gif while an applet is being loaded hardly solves anything.

The real fix is installing an applet splash screen loader as soon as possible, and doing some fancy smancy stuff. However this doesn’t fix the orangy java loader thingy (which you have “replaced” with a gif).

It might not really solve any technical issues (we have to wait for the new lightweight JVM for that), but as the previous comments show, it’s all about the user expirience. Because the JVM is initted with a small class it hangs only for a very brief period… which is better than the 10 seconds+ I’m getting at the average applet. Dynamically loading a new applet without leaving / refreshing the page is a welcome feature too. Hiding the hideous Java splash may be a no brainer, but it is something you need to take care of… Hopefully using a “standarized” little JS lib all applet developers will adopt this. Maybe making Java applets (initial) appearance on the par with Flash.

[quote]The real fix is installing an applet splash screen loader as soon as possible, and doing some fancy smancy stuff.
[/quote]
So, you’re talking about making, say, a tiny Bootstrap.jar which would show a fancy shmancy splash, with a progress bar, while the main game jars are downloaded? Unfortunately that requires creating a custom classloader, or doing other classloader tricks that you can’t do with the default applet permissions.

You can, however, keep game assets (not classes) in an external jar and show a fancy shmancy splash while those are loading.

?? dont really understand what you think… are you sure you know what you are talking about ??

basically it load JVM in memory using an applet with code=java.applet.Applet as

<APPLET WIDTH=0 HEIGHT=0 
 CODE = "java.applet.Applet" 
</APPLET>

this is the faster way to make JVM initialisation as low as possible

than once JVM is initialised, It allow loading Applet with another splash screen than the default one (grey area for MS and different animation fo SUN (an animated gif in my case a we dont know about time that would be spent), once applet is activated it resize and show it.

What it help in is to make a “near smooth” loading of applet that look a lot better than a simple applet tag, also it is full JavaScript and doesn’t requiere applet modifications.

It also help as there is no need to “click to activate control” …

EDIT:
It also try to load jar and class in browser cache using JavaScript…

so basically it help a lot ?! dont really understand your comment…

Another tip when using that approach: For downloading jar files this would mean they wont get cached (the plugin seems to refuse to cache any other extension than .class). A workaround is to rename your .jar to .class, download it over an urlconnection with setUseCache(true) and read its contents at runtime as zip file. It’s a bit hairy and unfortunatly it doesn’t allow you to read progress while downloading a .class file (due to a crappy implementation from Sun)

The problem with this approach - though it improves the user experience and is generally usable - it still hasn’t fixed anything. It’s all smoke and mirrors to hide the issues.

A proper solution requires the following:
1 - JVM initialization must not lock down the browser
Will be fixed by sun in the new Plugin architecture, afaik

2 - JVM Initialization must allow control over the ‘Java Loading’ process instead of showing generic Java logo
Somewhat fixed with special attributes - this is a chicken and egg issue since Ideally we’d like to run custom code - which isn’t loaded yet…

3 - Fast loading of JVM
“Solved” with the new Java Quickstart - available in Update N

4 - Run code as early as possible
This should run the bootstrap stuff that will create a nice splashscreen and transition to the actual content. Ideally this is pluggable, but currently this isn’t possible due to security reasons. Due to this security issue, we now have to wait for all of the code to load before running any code at all.

1,2,3 can be fixed by Sun.
4 is a bit more tricky. Maybe it should be possible to specify bootstrap jars or something like that.

yup but there will still be some user who dont have the lastest JVM with the lastest CG card and the lastest computer… etc…

logo are always differents depending on JVM vendor and version, this tool help you put your own

[quote]Run code as early as possible
[/quote]
already possible, depend on how your make your applet… you can simply load the smalest part you need than do dynamic loading for all others…

anyways, this script allow custom splash ans quite smooth loading looking as flash) without applets modification and works with all JVM, and I dont want to wait for JVM version 12… and have to make different Applet implementation depending on user JVM version.

[quote]it improves the user experience and is generally usable
[/quote]
this is the most important !!! every programmers have to keep it in mind! and if you can do that with most user including user that dont upgrade there JVM every day so it is the way to go.

NB: the animated gif is 2k so it is imediatly load even with a 56k modem

Well, what do you suggest? What is the best approach if you want to compete with your applet games against a flash site? Applets have a bad rep (compared to flash) because of browser freezing, ugly/non customized splash screen, and ofter ugly looking games. The last one can naturally only be fixed by constantly creating nice looking applet games. The first two only seems possible to fix with this/milpa approach. This approach also seems generic which is great. I agree that it would be great if sun would eradicate the problems, and it seems like there is some good progress, but it will still be some time until we can take advantage of that.

Agree with Thijs response. This example pretty much could have fooled any browser gamer into not realizing that it is an applet starting and that means that the major issue actually is solved. Replace the rotating image with a game co logo and anyone would be fine with starting a game like that. Unfortunately we still pretty much have to hide the fact that it is a java game for ppl to test them. If this is simple enough to use and works well, then maybe enough devs will use it and applet will become more mainstream and it will be easier for us to get our applet games out there.