Applet Loader

Download
Applet Loader

(6K)

This week there is an applet, named Applet Loader, that can't be used as an applet because of security problems with browsers. I tried to write very simple and small code with a Shell class derived from java.applet.Applet which calls a Loader derived from java.lang.ClassLoader to load several classes zipped in a file, but you can use them only with the appletviewer or in a real application because of the Security Manager of Navigator or Explorer.

This is not a real problem because my Applet Loader is overcomed: in fact, in the new JDK 1.1 you can find the ...JARS Files (Java Archive) that is a platform-independent file format that aggregates many files into one ... that can be downloaded to a browser in a single HTTP transaction, greatly improving the download speed. The JAR format also supports compression, which reduces the file size, further improving the download time... It is fully backward-compatible with existing applet code and is fully extensible, being written in Java... (JDK 1.1 Release Notes). Obviously, the JDK 1.1 is supported only by the latest versions of browsers.

However Applet Loader has some academic interest so I'm going to explain the capabilities of this beta and last version.

Installation

To install the program simply unzip it in a directory of your choice. Then open the Main.bat file and you'll see something like this

path=e:\bc5\java\bin;%path%
set classpath=e:\javaprog\Pack
java Pack zip %1 %2 %3 %4 %5 %6 %7 %8 %9

You have to write your path of the program instead of e:\javaprog\Pack and then substitute c:\bc5\java\bin with the directory in which you keep java.exe. I hope that all this will work properly. If you find any problem use the free consulting service. With the operations above you have installed the Pack application.

The PACK Application

With the PACK application you can zip together all the classes your applet needs. For example you have:

YourApplet.class (derived from java.applet.Applet) Class1.class Class2.class

To create the zip file simply write on the command line

Main YourApplet Class1 Class2

and a file named YourApplet.zip will be created. Note that YourApplet MUST be the first class of the list.

The only error that could be thrown during the zip file creation is Insufficient METAS, but this error is quite improbable with usual class files so I haven't fixed it yet.

Shell and Loader classes

Then you can store YourApplet.zip with Shell.class, Loader.class and your HTML file. The tag to be added in the HTML is the following

<applet code="Shell" width=400 height=300 align=center>
<param name=lib value="YourApplet.zip">
</applet>

You have only to change width, height, alignment and the name of YourApplet. Then you can use appletviewer to see if all this works well.

You can also use Loader.class in an application (in this case Shell.class is needless). This is the code in the Shell.class and it may help you in using Loader in applications:

String library = getParameter("lib");
try {
Applet applet = (Applet)new Loader(getCodeBase(),library).loadClass(library,true).newInstance();
setLayout(new BorderLayout());
add(applet);
applet.init();
applet.start();
} catch(Throwable e) {
// Loader exceptions handling
}

With this version of Applet Loader the compression is not fully optimized. In the worst case the file obtained is 10% greater than the one you have from other ZIP programs, but Pack and Loader can be specialized for class files and further improvements could be reached.


TETRACTYS Freeware Main Page

In the next Issue Weekly Applet will be

The Rotating Magnetic Field

GeoCities