MarvinSketch Example 1.1

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

<applet CODEBASE="../.." ARCHIVE="marvin.jar" CODE="MSketch" WIDTH=460 HEIGHT=380>
<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, marvin.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.

MarvinSketch/Swing has the same applet tag with minor differences: ARCHIVE="jmarvin.jar" and CODE="JMSketch.class".

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 Netscape or <object> for Microsoft. There are 6 possibilities overall:

  1. <applet ARCHIVE="marvin.jar"> and AWT
  2. <applet ARCHIVE="jmarvin.jar"> and Swing
  3. <embed> and AWT
  4. <embed> and Swing
  5. <object> and AWT
  6. <object> and Swing
Fortunately, this does not mean that you need to write the same HTML in 6 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"
// marvin_gui = "awt"; // "awt" or "swing"
msketch_begin("../..", 460, 380); // arguments: CODEBASE, WIDTH, HEIGHT
msketch_end();
//-->
</script>
The JVM (built-in or Java Plug-in) and the GUI (AWT or Swing) each 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 and/or marvin_gui. These settings 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", the gui parameter is "awt" or "swing". You can try it by appending "?jvm=plugin&gui=swing" or "?jvm=builtin&gui=awt" 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.

Warning: Scripting (JavaScript to Java communicaton) does not work in Netscape 4.x with the Java Plugin. In MarvinSketch, scripting is needed to query the molecule drawn by the user. So in practice, you should use the built-in JVM instead of the Java Plugin.


The next example introduces the use of applet parameters.