cello
Full Member
Offline
Posts: 143
Re: pre loader?
Reply #1 - Jan 6th , 2006, 12:13am
Unfortunately there is no good way to make a preloader in Java. The problem is that Java needs to load the classes itself before before it can execute them, but if you make a preloader, you have no control or access over that load operation to give some kind of progress. The best you can do in that respect is make a preload/splash screen that shows .jar files sequentially being loaded. Unfortunately, my attempts to trick java's cache by loading the .jar files directly, myself, then letting java pull them from cache for the actual class loading has not been successful. This makes it impossible to give a realistic progress bar. If you have multiple jar files, Java loads them in order until it finds the class you requested, if you try to request a class that doesn't exist, it'll load all the jar files first. You can use this to your advantage by requesting one class from each jar file, in order, and displaying a fairly chunky progress bar for each (you could even calculate the time to load the first jar file, and extrapolate the other jar files based on that to get a prediction). Ok, so that's the general method. There is one other method, and that involves using some special features in the Java plugin. You'll notice processing (in later builds) displays the logo while it's downloading the jar files. You can change the logo to anything you want, plus, in addition, if you look around, some versions of the java plugin allow you to specify a progress bar (color, position, etc.). I believe this feature was added in some 1.3.x release, changed in 1.4, and changed yet again in 1.5 (not sure if 1.5 lets you change it, I haven't looked recently). In short, there's no one good way to do it. The best you can do is make a mini class that tells the user that something is loading (although this won't be displayed until the JVM starts, one reason to use the method processing uses). That could even have some kind of animation, but there's no decent way (that I have found) to do a progress bar. Hope that helps! Maybe some other people have some advice or have thought about this. Marcello