Wrapping up

At the moment the example applet is part of the »Java default package« that is meant only for small tests. To put it into a package of its own - named physicsapplets - proceed as follows:

When you look at the first line of the source code, you will notice that NetBeans has automatically inserted the suitable command

  package physicsapplets;

Several class files have been created by the compilation: one for the »main class« Cart2Polar and one for each listener. In order that Cart2Polar can run as applet outside the NetBeans environment, all its class files have to be collected in one JAR file - a kind of zip file for Java classes. It can be created in the following way:

Now create a directory for the HTML files containing the applets, e.g. export, with a subdirectory archives, and copy the two required jar files myapplets.jar and physbeans.jar into it.

Finally you must create the HTML page, e.g. export/applet1.html. To include an applet in a standard conforming way one has to use - like with other multimedia elements - the tag <object>. Unfortunately the Internet Explorer doesn't interpret its attributes in the way, they were meant in the standard and are accepted by other browsers. Instead it reinterprets them in such a way that other browsers can't understand the code. A workaround has been invented by Sun: It combines two tags that both don't conform to an HTML standard, to create a page that should work with most browsers. You can find additional information on Sun's plugin page.

An HTML page containing a PhysBeans applet needs the following information:

For the example applet use the following values:

Copy now the template file template.html into the export directory, open it with any text editor, replace the five variables, which each appear twice, by the values given above, and save the file. If you now open the file with your browser, it should show the working applet.

By the way, all PhysBeans programs can be executed as self-contained applications, without any browser. To check that, open a command window, change into the directory export/archives and enter (under Windows):

  java -cp physbeans.jar;myapplets.jar physicsapplets.Cart2Polar

Under Linux one uses a different character to separate the jar files, here you have to enter:

  java -cp physbeans.jar:myapplets.jar physicsapplets.Cart2Polar

This will open a window of the correct size with the program Cart2Polar running in it. This is the only reason for the size specification in the program; the applet only uses the values given in the HTML file. If the program doesn't start, check whether the java program is in your search path. If not, add the complete path to the command. If you get the error message

  Unsupported major.minor version

then you have installed several versions of the Java SDK and adressed an older version with your search path. Change the path accordingly, so that the newer version is found first, or enter the explicit path to the correct version.

ZurückWeiter