Applications and Applets:
Application Applet

Applets

Java applets are programs that run within a web browser using  the Sun Applet API.   It is straightforward to create attractive applets that rival the functionality of Java applications and the OSP library can be used to write stand Java applets.  Each applet is unique and is embedded into an html page using the standard applet tag.   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.)

An alternative approach to applets is to create a general purpose applet that runs Java applications.  Two of our applets, Application Applet and EmbeddingApplet, create (instantiate) Java applications that are specified using a parameter tag.  The advantage of this generic approach is that the program author creates only one version of program and need not concern him/herself with the Applet API.  The same code runs both as a stand-alone application, a Web Start application, or as an applet.

Application Applet

ApplicationApplet acts as an intermediary that invokes an application's main method.  This applet runs a Java application from within a web page but, because html pages cannot be trusted to be safe, the browser imposes tight security restrictions.  This applet is embedded using the standard html applet tag:

<applet code="org.opensourcephysics.davidson.applets.ApplicationApplet.class" 
  archive="osp_demo.jar"
  name="nbody0"
  width="150" height="40"
  align="top" codebase="jars" />

  <param name="target" value="org.opensourcephysics.davidson.nbody.OrbitApp" />
  <param name="xmldata" value="binary4.xml" />

</applet>

The target parameter 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 OrbitApp application.  Note that the only the parameter tags are changed to change the initial conditions or to execute a different OSP application.