ibm-information-center/dist/eclipse/plugins/i5OS.ic.rzahh_5.4.0.1/pdmlbrws.htm

259 lines
12 KiB
HTML

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en-us" xml:lang="en-us">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="security" content="public" />
<meta name="Robots" content="index,follow" />
<meta http-equiv="PICS-Label" content='(PICS-1.1 "http://www.icra.org/ratingsv02.html" l gen true r (cz 1 lz 1 nz 1 oz 1 vz 1) "http://www.rsac.org/ratingsv01.html" l gen true r (n 0 s 0 v 0 l 0) "http://www.classify.org/safesurf/" l gen true r (SS~~000 1))' />
<meta name="DC.Type" content="reference" />
<meta name="DC.Title" content="Using the Graphical Toolbox in a browser" />
<meta name="abstract" content="You can use the Graphical Toolbox to build panels for Java applets that run in a Web browser." />
<meta name="description" content="You can use the Graphical Toolbox to build panels for Java applets that run in a Web browser." />
<meta name="DC.Relation" scheme="URI" content="pdmlpg1.htm" />
<meta name="copyright" content="(C) Copyright IBM Corporation 2006" />
<meta name="DC.Rights.Owner" content="(C) Copyright IBM Corporation 2006" />
<meta name="DC.Format" content="XHTML" />
<meta name="DC.Identifier" content="pdmlbrws" />
<meta name="DC.Language" content="en-us" />
<!-- All rights reserved. Licensed Materials Property of IBM -->
<!-- US Government Users Restricted Rights -->
<!-- Use, duplication or disclosure restricted by -->
<!-- GSA ADP Schedule Contract with IBM Corp. -->
<link rel="stylesheet" type="text/css" href="./ibmdita.css" />
<link rel="stylesheet" type="text/css" href="./ic.css" />
<title>Using the Graphical Toolbox in a browser</title>
</head>
<body id="pdmlbrws"><a name="pdmlbrws"><!-- --></a>
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
<h1 class="topictitle1">Using the Graphical Toolbox in a browser</h1>
<div><p>You can use the Graphical Toolbox to build panels for Java™ applets
that run in a Web browser. </p>
<div class="section"><p>This section describes how to convert the simple panel from the <a href="pdmlcdex.htm#pdmlcdex">Graphical Toolbox Example</a> to run in a
browser. The minimum browser levels supported are Netscape 4.05 and Internet
Explorer 4.0. In order to avoid having to deal with the idiosyncrasies of
individual browsers, it is recommend that your applets run using Sun's Java Plug-in.
Otherwise, you will need to construct signed JAR files for Netscape, and separate
signed CAB files for Internet Explorer.</p>
<div class="note"><span class="notetitle">Note:</span> Read the <a href="codedisclaimer.htm#codedisclaimer">Code
example disclaimer</a> for important legal information.</div>
</div>
<div class="section"><h4 class="sectiontitle">Constructing the applet</h4><p>The code to display a panel
in an applet is nearly identical to the code used in the Java application
example, but first, the code must be repackaged in the <strong><span>init</span></strong> method
of a <strong>JApplet</strong> subclass. Also, some code was added to ensure that the
applet panel is sized to the dimensions specified in the panel's PDML definition.
Here is the source code for the example applet, <strong>SampleApplet.java</strong>.</p>
<pre>import com.ibm.as400.ui.framework.java.*;
import javax.swing.*;
import java.awt.*;
import java.applet.*;
import java.util.*;
public class SampleApplet extends JApplet
{
// The following are needed to maintain the panel's size
private PanelManager m_pm;
private Dimension m_panelSize;
// Define an exception to throw in case something goes wrong
class SampleAppletException extends RuntimeException {}
public void init()
{
System.out.println("In init!");
// Trace applet parameters
System.out.println("SampleApplet code base=" + getCodeBase());
System.out.println("SampleApplet document base=" + getDocumentBase());
// Do a check to make sure we're running a Java virtual machine that's compatible with Swing 1.1
if (System.getProperty("java.version").compareTo("1.1.5") &lt; 0)
throw new IllegalStateException("SampleApplet cannot run on Java VM version " +
System.getProperty("java.version") +
" - requires 1.1.5 or higher");
// Instantiate the bean object that supplies data to the panel
SampleBean bean = new SampleBean();
// Initialize the object
bean.load();
// Set up to pass the bean to the panel manager
DataBean[] beans = { bean };
// Update the status bar
showStatus("Loading the panel definition...");
// Create the panel manager. Parameters:
// 1. PDML file as a resource name
// 2. Name of panel to display
// 3. List of data objects that supply panel data
// 4. The content pane of the applet
try { m_pm = new PanelManager("MyGUI", "PANEL_1", beans, getContentPane()); }
catch (DisplayManagerException e)
{
// Something didn't work, so display a message and exit
e.displayUserMessage(null);
throw new SampleAppletException();
}
// Identify the directory where the online help resides
m_pm.setHelpPath("http://MyDomain/MyDirectory/");
// Display the panel
m_pm.setVisible(true);
}
public void start()
{
System.out.println("In start!");
// Size the panel to its predefined size
m_panelSize = m_pm.getPreferredSize();
if (m_panelSize != null)
{
System.out.println("Resizing to " + m_panelSize);
resize(m_panelSize);
}
else
System.err.println("Error: getPreferredSize returned null");
}
public void stop()
{
System.out.println("In stop!");
}
public void destroy()
{
System.out.println("In destroy!");
}
public void paint(Graphics g)
{
// Call the parent first
super.paint(g);
// Preserve the panel's predefined size on a repaint
if (m_panelSize != null)
resize(m_panelSize);
}
}</pre>
<p>The applet's content pane is passed to the Graphical Toolbox
as the container to be laid out. In the <strong>start</strong> method, the applet pane
is set to its correct size, and then override the <strong>paint</strong> method in order
to preserve the panel's size when the browser window is resized.</p>
<p>When
running the Graphical Toolbox in a browser, the HTML files for your panel's
online help cannot be accessed from a JAR file. They must reside as separate
files in the directory where your applet resides. The call to <strong><span>PanelManager.setHelpPath</span></strong> identifies
this directory to the Graphical Toolbox, so that your help files can be located.</p>
</div>
<div class="section"><h4 class="sectiontitle">HTML tags</h4><p>Because it is recommended to use Sun's Java Plug-in
to provide the correct level of the Java runtime environment, the HTML for identifying
a Graphical Toolbox applet is not as straightforward as preferred. Fortunately,
the same HTML template may be reused, with only slight changes, for other
applets. The markup is designed to be interpreted in both Netscape Navigator
and Internet Explorer, and it generates a prompt for downloading the Java Plug-in
from Sun's Web site if it's not already installed on the user's machine.
For detailed information on the workings of the Java Plug-in see the <a href="http://java.sun.com/products/plugin/1.1.3/docs/tags.html" target="_blank">Java Plug-in
HTML Specification</a>. <img src="www.gif" alt="Link outside Information Center" /> </p>
<p>Here is the HTML for the sample applet,
in the file <strong>MyGUI.html</strong>:</p>
<pre>&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Graphical Toolbox Demo&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;h1&gt;Graphical Toolbox Demo Using Java(TM) Plug-in&lt;/h1&gt;
&lt;p&gt;
&lt;!-- BEGIN JAVA(TM) PLUG-IN APPLET TAGS --&gt;
&lt;!-- The following tags use a special syntax which allows both Netscape and Internet Explorer to load --&gt;
&lt;!-- the Java Plug-in and run the applet in the Plug-in's JRE. Do not modify this syntax. --&gt;
&lt;!-- For more information see http://java.sun.com/products/jfc/tsc/swingdoc-current/java_plug_in.html.--&gt;
&lt;OBJECT classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"
width="400"
height="200"
align="left"
codebase="http://java.sun.com/products/plugin/1.1.3/jinstall-113-win32.cab#Version=1,1,3,0"&gt;
&lt;PARAM name="code" value="SampleApplet"&gt;
&lt;PARAM name="codebase" value="http://www.mycompany.com/~auser/applets/"&gt;
&lt;PARAM name="archive" value="MyGUI.jar,jui400.jar,util400.jar,x4j400.jar"&gt;
&lt;PARAM name="type" value="application/x-java-applet;version=1.1"&gt;
&lt;COMMENT&gt;
&lt;EMBED type="application/x-java-applet;version=1.1"
width="400"
height=200"
align="left"
code="SampleApplet"
codebase="http://www.mycompany.com/~auser/applets/"
archive="MyGUI.jar,jui400.jar,util400.jar,x4j400.jar"
pluginspage="http://java.sun.com/products/plugin/1.1.3/plugin-install.html"&gt;
&lt;NOEMBED&gt;
&lt;/COMMENT&gt;
No support for JDK 1.1 applets found!
&lt;/NOEMBED&gt;
&lt;/EMBED&gt;
&lt;/OBJECT&gt;
&lt;!-- END JAVA(TM) PLUG-IN APPLET TAGS --&gt;
&lt;p&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>
<p> It is important that the version information be
set for 1.1.3. </p>
<div class="note"><span class="notetitle">Note:</span> In this example, the XML parser JAR file, <strong>x4j400.jar</strong>,
is stored on the Web server. You can use other XML parsers. For more information,
see <a href="rzahhxmlparserxslprocessor.htm">XML parser and XSLT processor</a>.
This is required only when you include your PDML file as part of your applet's
installation. For performance reasons, you would normally <em>serialize</em> your
panel definitions so that the Graphical Toolbox does not have to interpret
the PDML at runtime. This greatly improves the performance of your user interface
by creating compact binary representations of your panels. For more information
see the description of <a href="pdmltool.htm#pdmltool__genf">files generated
by the tools</a>.</div>
</div>
<div class="section"><h4 class="sectiontitle">Installing and running the applet</h4><p>Install the applet
on your favorite Web server by performing the following steps: </p>
<ol><li>Compile <strong>SampleApplet.java</strong>.</li>
<li>Create a JAR file named <strong>MyGUI.jar</strong> to contain the applet binaries.
These include the class files produced when you compiled <strong>SampleApplet.java</strong> and <strong>SampleBean.java</strong>,
the PDML file <strong>MyGUI.pdml</strong>, and the resource bundle <strong>MyGUI.properties</strong>.</li>
<li>Copy your new JAR file to a directory of your choice on your Web server.
Copy the HTML files containing your online help into the server directory.</li>
<li>Copy the Graphical Toolbox JAR files into the server directory.</li>
<li>Finally, copy the HTML file <strong>MyGUI.html</strong> containing the embedded
applet into the server directory.</li>
</ol>
<div class="tip"><span class="tiptitle">Tip:</span> When testing your applets, ensure that you have removed
the Graphical Toolbox jars from the CLASSPATH environment variable on your
workstation. Otherwise, you will see error messages saying that the resources
for your applet cannot be located on the server.</div>
<p>Now you are ready
to run the applet. Point your Web browser to <strong>MyGUI.html</strong> on the server.
If you do not already have the Java Plug-in installed, you will be asked
if you want to install it. Once the Plug-in is installed and the applet is
started, your browser display should look similar to the Figure 1:</p>
<p><strong>Figure
1: Running the sample applet in a browser</strong></p>
<p><img src="rzahh100.gif" alt="Running the sample applet in a browser" /></p>
</div>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="pdmlpg1.htm" title="The Graphical Toolbox, a set of UI tools, makes it easy to create custom user interface panels in Java.">Graphical Toolbox and PDML</a></div>
</div>
</div>
</body>
</html>