Using the Java
Plug-in Converter
The Painless
Way to Activate Swing Applets
There are several ways to create and implement JavaTM
applets that make use of Swing components, and this article describes
the easiest method we´ve run across so far. The article was contributed
by Nancy Schorr, a member of the Swing team.
By Nancy Schorr
The
easiest way to create an HTML page that enables Java Plug-in is
to use the JavaTM Plug-in HTML
Converter that´s available for downloading on the Java
Plug-in Web site. Here at Sun, we test Java Plug-in in many
different configurations, so we have to create many pages that enable
Java Plug-in.
After the HTML Converter works its magic, we rarely, if ever, have
to edit the pages it generates. In fact, editing the Converter´s
work is not recommended unless you're certain you know what you're
doing. The technology behind the plug-in (presented in some detail
in the "Plugging
into Swing" article) is a bit complicated for the novice,
so we highly recommend that you use the Converter.
Downloading the HTML Converter
You can download the Java Plug-in
HTML Converter from
http://java.sun.com:80/products/plugin/converter.html
You can also reach it from links on the
Java Plug-in page:
http://java.sun.com:80/products/plugin/index.html
The HTML Converter Tutorial
When you have downloaded the HTML
Converter, these are the steps to convert a plain applet page to
an applet page that enables Java Plug-in:
- First, create an ordinary HTML page, complete
with all text and pictures that you want your page to contain.
- Now forget about the fact that you are
going to be using the Converter, and provide your HTML page with
any applet tags that you would normally need to make your applet
to show up on your page. For instance, here is a set of tags that
you could use to enable the SwingSet program (the main example
program that comes with Swing) as an applet:
<html>
<head> <title>SwingSet demo</title>
</head>
<body>
<h1>SwingSet demo</h1>
<applet code=SwingSetApplet codebase=classes archive=SwingSet.jar
width=695 height=525>
</applet>
</body> </html>
Once you have placed a pair
of <applet>
and </applet>
tags on your pages, as shown in the preceding HTML snippet, you´re
ready to run your page through the HTML Converter. The Converter
will then automatically convert the <applet>
and </applet>
tags in your HTML page to the kinds of tags that Java Plug-in
recognizes.
When you run the Converter, it will copy your original file to
a backup file, and create a new file with the same name that your
original file had. That way, you will still have your original
file after you run the Converter.
The next thing you must do, then, is start the Converter. This
process differs for Windows users and UNIX users, so we have split
the next part of this tutorial into the two subsections that follow.
Starting the HTML Converter under Windows
Here is a simple set of instructions for
starting the HTML Converter application under Windows 95/NT/98:
Because the HTML Converter is a Java application,
you must have a copy of the JDK available to your machine -- preferably
JDK 1.1.5 or later. You must also make sure that your CLASSPATH
and PATH variables
are set correctly, as explained in the README.txt
file that comes with Swing.
On a Windows computer system equipped with JDK 1.1.x, it´s
easy to create a batch file that sets all necessary system and
local variables, and then launches the Converter. Here is such
a batch file, named Converter.bat:
set
CONVERTER=E:\HTML_Converter\Convert.jar;
E:\HTML_Converter\templates
set JAVA_HOME=D:\jdk1.1.6
set CLASSPATH=.;%CONVERTER%;%JAVA_HOME%\lib\classes.zip
set path=%JAVA_HOME%\bin;%path%
java JAConverter
If you´re using JDK 1.2 (currently
available in a release-candidate version from the Java
Software Web site), you do the same
thing, except that you omit the CLASSPATH
pointer to classes.zip:
set
CONVERTER=E:\HTML_Converter\Convert.jar;
E:\HTML_Converter\templates
set JAVA_HOME=D:\jdk1.2
set CLASSPATH=.;%CONVERTER%
set path=%JAVA_HOME%\bin;%path%
java JAConverter
Starting
the HTML Converter on Solaris
On Solaris, you can start the Converter
using a batch file that looks like this (it must be executed from
the directory in which you have placed the HTML Converter):
#!/bin/sh
CONVERTER=/home/nancys/HTML_Converter/Convert.jar:/home/nanc ys/HTML_Converter/templates
JAVA_HOME=/usr/local/java/jdk1.1.6/solaris
export JAVA_HOME
CLASSPATH=${CONVERTER}:.:${JAVA_HOME}/lib/classes.zip
export CLASSPATH
${JAVA_HOME}/bin/java JAConverter
The
result
Once you have launched the Converter application,
you'll see a display that looks something like this (the one shown
was executed under a prerelease version of JDK 1.2):
Using the HTML Converter
When
you have started the HTML Converter, the easiest way to convert
files is to perform your conversions one file at a time -- even
though the default is to convert all files in a folder. To convert
a file using the HTML Converter, these are the steps to follow.
- To convert a single file, click the radio
button labeled One File, as shown in the preceding screen
shot. Then use the Browse button to navigate
to the file you want to convert, and select it. When you have
selected a file, you´ll see its name displayed in the text field
to the right of the One File button.
- In the lower part of the Converter window,
there is a pair of text boxes labeled Backup Files to Folder and
Generate Log File. Notice that by
default, the Converter creates a backup folder in the HTML_Converter
folder, and creates a Log File in the HTML_Converter folder. Leave
these two choices the way they are unless you really need to change
them.
- Now you´re ready to pick a template. Again,
the easiest thing to do is to leave the Template File control
at the default setting, which is Standard -- a setting that works
for the Netscape Navigator and Internet Explorer browsers on Windows
and Solaris only. An alternative is to select Extended -- a setting
that works for all browsers on all platforms.
- Finally, click the Convert button in the
bottom right corner of the screen. A progress dialog appears,
and then starts reporting the progress of the Converter as it
converts your file.
- When conversion is complete, close the
progress dialog by clicking the Done button. You can then find
your converted HTML file in the same location as your original
file. Your converted file will also have the same name as your
original file. You can find your
original file in the backup folder that the Java HTML Converter
has created.
|