3DzzD - Applet Boot V2 updated

Hi DzzD,

Thanks for making this applet loader, it looks very cool 8) I’m using it to try and run a simple non-signed applet with a custom loading image.

I put the source given in your first post for ‘Boot.java’ in my IDE but it can’t find ‘BootClassLoader’. So I downloaded the ‘full demo’ to see the full source but it’s not there. Could you please post the code for BootClassLoader?

Thanks,
Keith

PS: I’m trying to get a custom gif image to display instead of the coffe cup during loading. Using isn’t working for me for some reason. The tutorial here (http://java.sun.com/docs/books/tutorial/deployment/deploymentInDepth/customizeLoadingScreen.html) needs the Java Deployment Toolkit which firefox has apparently disabled (http://www.java-gaming.org/index.php/topic,22230.msg184620.html#msg184620). That’s why I’m going with the solution posted here

thks, this class is not requiere for unsigned Applet just remove this line “ucl = new BootClassLoader ( urlJars );” and the associated try…catch

anyway here is its source code, it is intended to give full right to the applet to enable the use of signed/unsigned jars in the archive PARAM of the applet with only one security popup (wich appear if boot.jar is signed)

BootClassLoader .java


import java.net.*;
import java.security.*;

public class BootClassLoader  extends URLClassLoader 
{
    public BootClassLoader(URL[] urls) 
    {
    	super(urls);
    	Thread.currentThread().setContextClassLoader( this );
    	System.setSecurityManager(new MySecurityManager());
    }
    
    private class MySecurityManager extends SecurityManager
	{
		public MySecurityManager() 
		{
			super();
		}

		public void checkPermission(Permission perm) throws SecurityException, NullPointerException {
		}

		public void checkPermission(Permission perm, Object context) throws SecurityException, NullPointerException {
		}
	}
}

Thanks a lot, very neat.

Mind if I ask a few questions?
Is this correct:
a. the Boot applet loads itself and paints the loading graphic.
b. While painting, it downloads the other jars using URLClassLoader.
c. Once downloaded, the applet ‘a’ is setup to have the same state as the boot applet, including size, AppletStub, etc.
d. Then the Applet a is added to the boot applet’s inner java.awt.Container,
e. and then thread that was painting the boot applet is stopped.

Another thing, while I haven’t seen the default java coffee cup loading logo on your demo applet, isn’t there a chance it will be displayed while the initial boot.jar is downloaded?

Thanks Bruno, great work here :slight_smile:
Keith

happy you found it usefull :slight_smile:

you’re alright about the process, another step is that the boot applet component is removed from its parent container when the sub-applet “a” is added

there is few chance yes but it will never be show for a long time, inded it is better to let an image parameter to the applet : a plain color image (image file size will just be few bytes) as the html web page background color maybe nice to replace in some case (when it is working) the few seconds java plugin loading animation

NB: something that should really be added is setUncaucghtExceptionHandler to the thread that load the applet a , so you can do something when the applet crash like display the user a message to propose to restart the applet or to send a bug report or anything else

I’ve been trying to get a custom loading image to show up but haven’t succeeded, it just shows a grey background with no loading graphic - not the default one or the gif i told it to use.

By the way, tt the start of the run() method you have a short sleep, what is that for?

public void run() {
try {
	Thread.sleep(100);
	String bootArchive = Boot.this.getParameter("BOOTJARS");

Keith :slight_smile:

as I remember the sleep was to test the loader (have some time to see what the loading look like), It can be safely removed. probably the image take some time to load, try to make the boot.class implements ImageObserver and in the ImageObserver updateImage method do your image paint and return !this.isLoaded so it will be called periodically for animated gif until applet is loaded.

also remember that you must use parent graphics stored in this.g or this.c.getGraphics() and that if the anim thread is running (the one who draw the circle) it will paint over your gif

Thanks a lot for your help, I’ll try it out :slight_smile:

I use a modified version of this boot loader here. I haven’t added the plugin replacement image, but I never see the spinning java logo, but it can be because I “sit so close to the server”. Would be interesting to hear how it loads for you.

I could also show the code, if that is what you wanted to do, but I think that DzzD planned to do something better than what I have done, so I was actually planning to replace my code with his when that is done. The plan is then to use the same boot loader for all java games on the site, so that the loader will appear really fast.

I get a page with a blank space where the applet should be for about 15 seconds, then the loading image fires up then the game starts. I think the long initial delay is because in your applet tag you put all the jars in the ‘archive’ parameter which means that they are all downloaded. In DzzD’s latest version only the small boot.jar is in the archive, the other jars are downloaded by the URLClassLoader while the animation is shown.

Here’s a demo I made using the boot loader code:

http://keithphw.freehostia.com/LineOfSightApplet/

This is what I see when I load it:
The java coffee cup for a second, but sometimes it’s not shown which is good.
Then the spinning white animation of the boot.jar.
Then that animation freezes for about 5 seconds until the main applet starts painting.

It’s unfortunate about that 5 second freeze. It occurs because my main applet takes ages to execute the code in the constructor and the thread seems to take a very long time to start - which is strange because when it is run as a normal app in a JFrame rather than an Applet it starts instantly… weird :-\

PS: I added AppletBoot.this.a.invalidate(); and AppletBoot.this.a.validate(); after the call to AppletBoot.this.a.resize(new Dimension(AppletBoot.this.w(), AppletBoot.this.h())); to get everything to lay itself out properly.

Thanks for the report! It looked so good from here I was almost starting to think that some magic happened to make the preloading happen during the loading animation. I have not been able to use v2 of the boot, because I can’t access resources as I used to.

Thread.currentThread().getContextClassLoader().getResourceAsStream(resource)

dosen’t find the stuff from “BOOTJARS”. The console just freezes, but I think that is the problem. I guess they are only available from another thread/classloader. Not sure if I made some mistake somewhere along the line. Suggestions are welcome. I guess it might be time for me to learn about classloaders…

Pretty cool applet 8)
It seems like it loads some more things after the start of the applet:

LineOfSightApplet: contructor begin
network: Cache entry not found [url: http://keithphw.freehostia.com/LineOfSightApplet/test/LineOfSightApplet$1.class, version: null]
network: Connecting http://keithphw.freehostia.com/LineOfSightApplet/test/LineOfSightApplet$1.class with proxy=DIRECT
network: Connecting http://keithphw.freehostia.com:80/ with proxy=DIRECT
.
.
.

Uh huh! Thanks :slight_smile: I never knew about setting the trace level on the console. Well that explains the 5 second gap - the URLClassLoader is downloading the classes it needs to do the run method. Pity there’s no way to load them all before hand without manually doing ‘loadClass(classNameString)’ for each class. Hm, the time taken for the URLClassLoader to download each little class separately must be pretty inefficient.

Maybe try accessing them directly from the URLClassLoader which loads the rest of your app?
It’s declared in this line:

ucl = ((URLClassLoader) Thread.currentThread().getContextClassLoader()).newInstance(urlJars);

Then call

ucl.getResourceAsStream(resource);

I have only got problem on ressource when I run Applet locally (AccesControlException because the protocole is file) in other case (when online) it strangely works well…

Plz if you make significant change/improvment post it somewhere, maybe as this code is pretty short & simple we could use Jojoh Wiki and make modification on it, Wiki is nice as it enable history & discussion. Also I propose to put the BootClassLoader as an inner class so the whole code will be only one file (usually not very clean to do that but in this case it make sens).

A target I think good to keep in minds for the loader are : be generic & compatible with the lowest java version possible, inded it is also important that it become robust & stable (must never crash) as an applet crashing is not that bad if the user is well informed.

finally the ultimate goal would be to have a very generic “shell/container” for applet enabling better user experience on applet start aswell as applet crash

For sure. I haven’t changed much, just the invalidate/validate thing I mentioned already.
There are 3 problems which I’d like to look into.
How to load all the classes before the main application starts - currently they’re only downloaded on-the-fly as needed.
How to avoid having to re-download the jars every time the applet is reloaded.
Getting rid of the coffee cup animation at the very start

Thanks for the help :slight_smile: