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:
The<applet CODEBASE="../.." ARCHIVE="marvin.jar" CODE="MSketch" WIDTH=460 HEIGHT=380> <strong>(YOU CANNOT SEE A JAVA APPLET HERE)</strong> </applet>
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:
<applet ARCHIVE="marvin.jar">
and AWT<applet ARCHIVE="jmarvin.jar">
and Swing<embed>
and AWT<embed>
and Swing<object>
and AWT<object>
and SwingThe 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<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>
marvin_jvm
and/or
marvin_gui
. These settings can also be overridden by writing
CGI-like parameters in the URL of the page:
The jvm parameter is "<a HREF="sketcherpage.html?jvm=plugin&gui=swing">click here!</a>
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.