Java applets are programs that run within a web browser. It is straightforward to create attractive applets that rival the functionality of Java applications and the OSP library can be used to write standard Java applets. Because of technical differences, it is not possible to embed a standard Java application in a web page. An application starts by executing a static "main" method whereas an applet is instantiated by a web browser that then calls the applet's init method. (It is possible to write programs that conform to both the Java Applet and Application API.
The approach shown here uses the OSP Application Applet to execute a Java application that is packaged in a jar file. The advantage of this generic approach is that clicking on a button mimics a Java application. The program author creates a java Application and need not concern him/herself with the Applet API. The same simulation runs as a stand-alone application and as an applet.
Example: More than one Application Applet can be embedded into an html page. The classical-physics classical-physics Helium Model is executed in this example. Pressing the applet's button executes the Java application.
Application Applet Parameters
The OSP Application Applet acts as an intermediary that invokes an application's main method. For example, the Classical Helium application is embedded into this html page using the standard applet tag:
<applet code="org.opensourcephysics.davidson.applets.ApplicationApplet.class" archive="mech_helium.jar" name="braided" width="150" height="40" align="top" codebase="jars"> <param name="target" value="org.opensourcephysics.davidson.twobody.HeliumWRApp" /> <param name="xmldata" value="braided.xml" /> <param name="title" value="Braided Orbit" /> <param name="singleapp" value="true" /> <param name="permissions" value="sandbox" /> </applet>
The target tag specifies the name of the application that will be run by the ApplicationApplet. The xmldata tag specifies an initialization data file that will be passed to the HeliumWRApp application. The xmldata tag specifies text that will appear on the applet's button. And the The singleapp tag specifies that only a single application may run at one time. Modify these parameter tags to change the initial conditions or to execute a different OSP application.
Note: A Java applet running within a web page can be a security threat. You should trust the author/originator of the applet and the applet should be signed with a security certificate.