MarvinSketch Example 1.1

The traditional way to put the MarvinSketch applet to a web page is by writing the following text in the HTML:

<applet CODEBASE="../.." ARCHIVE="jmarvin.jar" CODE="JMSketch" WIDTH=540 HEIGHT=480>
<strong>(YOU CANNOT SEE A JAVA APPLET HERE)</strong>
</applet>
The CODEBASE option specifies the directory of the Marvin binaries relative to the HTML file. This HTML file is in a subdirectory of the Marvin binaries directory, that's why we use "../.." here. The ARCHIVE option is needed to speed up the downloads. The program code is packaged into a compressed JAR file, jmarvin.jar. The text "(YOU CANNOT SEE A JAVA APPLET HERE)" is displayed if someone tries to see the web page with a browser that is not Java compatible.

If you want your page to work with Sun's Java Plugin, then the situation becomes more complicated, because instead of the standard <applet> tag, you have to use platform dependent solutions, <embed> for Firefox (mozilla) or <object> for Microsoft Internet Explorer. There are 3 possibilities overall:

  1. <applet ARCHIVE="jmarvin.jar">
  2. <embed>
  3. <object>
Fortunately, this does not mean that you need to write the same HTML in 3 different versions. All the possibilities can be combined in one page using the utility functions in marvin.js.
<script LANGUAGE="JavaScript1.1" SRC="../../marvin.js"></script>
<script LANGUAGE="JavaScript1.1">
<!--
// marvin_jvm = "builtin"; // "builtin" or "plugin"
msketch_begin("../..", 540, 480); // arguments: CODEBASE, WIDTH, HEIGHT
msketch_end();
//-->
</script>
The JVM (built-in or Java Plug-in) have a default value based on your browser and Java version. If you want to use a different configuration, you have to specify the marvin_jvm. This setting can also be overridden by writing CGI-like parameters in the URL of the page:
<a HREF="sketcherpage.html?jvm=plugin&gui=swing">click here!</a>
The jvm parameter is "builtin" or "plugin". You can try it by appending "?jvm=plugin" or "?jvm=builtin" to the URL of this page and then loading it again.

Note that in some browsers (such as MSIE) this method does not work if the page is on a local drive, because document.location.search is an empty string. But if you put the HTML file and the applet on a web server, then it should work.

 

The next example introduces the use of applet parameters.