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

177 lines
9.5 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="Example: Displaying a list of server jobs in a GUI" />
<meta name="abstract" content="" />
<meta name="description" content="" />
<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="guiex1" />
<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>Example: Displaying a list of server jobs in a GUI</title>
</head>
<body id="guiex1"><a name="guiex1"><!-- --></a>
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
<h1 class="topictitle1">Example: Displaying a list of server jobs in a GUI</h1>
<div><p></p>
<div class="section"><p>Use the following as an example for your program.</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>
<pre>//////////////////////////////////////////////////////////////////////////////////
//
// Example using the IBM Toolbox for Java's vaccess
// class, VJobList.
//
// This source is an example of IBM Toolbox for Java "Job List".
//
//////////////////////////////////////////////////////////////////////////////////
package examples; <a href="#guiex1__dup0036">Note 1 </a>
import com.ibm.as400.access.*;
import com.ibm.as400.vaccess.*; <a href="#guiex1__dup0037">Note 2 </a>
import javax.swing.*; <a href="#guiex1__dup0038">Note 3 </a>
import java.awt.*;
import java.awt.event.*;
public class GUIExample
{
public static void main(String[] parameters) <a href="#guiex1__dup0039">Note 4 </a>
{
GUIExample example = new GUIExample(parameters);
}
public GUIExample(String[] parameters)
{
try <a href="#guiex1__dup0040">Note 5 </a>
{
// Create an AS400 object.
//The system name was passed as the first command line argument.
AS400 system = new AS400 (parameters[0]); <a href="#guiex1__dup0041">Note 6 </a>
VJobList jobList = new VJobList (system); <a href="#guiex1__dup0042">Note 7 </a>
// Create a frame.
JFrame frame = new JFrame ("Job List Example"); <a href="#guiex1__dup0043">Note 8 </a>
// Create an error dialog adapter. This will display any errors to the user.
ErrorDialogAdapter errorHandler = new ErrorDialogAdapter (frame); <a href="#guiex1__dup0044">Note 9 </a>
// Create an explorer pane to present the job list.
AS400ExplorerPane explorerPane = new AS400ExplorerPane (jobList); <a href="#guiex1__ten">Note 10 </a>
explorerPane.addErrorListener (errorHandler); <a href="#guiex1__eleven">Note 11 </a>
// Use load to load the information from the system.
explorerPane.load(); <a href="#guiex1__twelve">Note 12 </a>
// When the frame closes, exit the program.
frame.addWindowListener (new WindowAdapter () <a href="#guiex1__thirteen">Note 13 </a>
{
public void windowClosing (WindowEvent event)
{
System.exit(0);
}
} );
// Layout the frame with the explorer pane.
frame.getContentPane().setLayout(new BorderLayout() );
frame.getContentPane().add("Center", explorerPane); <a href="#guiex1__fourteen">Note 14 </a>
frame.pack();
frame.show(); <a href="#guiex1__fifteen">Note 15 </a>
}
catch (Exception e)
{
e.printStackTrace(); <a href="#guiex1__sixteen">Note 16 </a>
}
System.exit(0); <a href="#guiex1__seventeen">Note 17 </a>
}
}</pre>
</div>
<div class="section"><ol><li id="guiex1__dup0036"><a name="guiex1__dup0036"><!-- --></a>This class is in the examples package. Java™ uses
packages to avoid name conflicts between Java class files.</li>
<li id="guiex1__dup0037"><a name="guiex1__dup0037"><!-- --></a>This line makes all of the IBM<sup>®</sup> Toolbox for Java classes in the vaccess package available
to this program. The classes in the vaccess package have the common prefix
com.ibm.as400.vaccess. By using an import statement, the program calls the
name instead of the package plus name. For example, you can reference the
AS400ExplorerPane class by using AS400ExplorerPane, not com.ibm.as400.AS400ExplorerPane.</li>
<li id="guiex1__dup0038"><a name="guiex1__dup0038"><!-- --></a>This line makes all of the Java Foundation Classes (JFC) in the Swing
package available to this program. Java programs that use the IBM Toolbox for Java vaccess
(GUI) classes need JDK 1.1.2 plus Java Swing 1.0.3 from Sun Microsystems,
Inc. Swing is available with Sun's JFC 1.1.</li>
<li id="guiex1__dup0039"><a name="guiex1__dup0039"><!-- --></a>This class has a main method so it can be run as an application.
To invoke the program, run "java examples.GUIExample serverName", where serverName
is the name of your server. Either the jt400.zip or jt400.jar must be in
your classpath for this to work.</li>
<li id="guiex1__dup0040"><a name="guiex1__dup0040"><!-- --></a>The IBM Toolbox for Java code throws exceptions that your program
must catch.</li>
<li id="guiex1__dup0041"><a name="guiex1__dup0041"><!-- --></a>The AS400 class is used by IBM Toolbox for Java. This class manages sign-on information,
creates and maintains socket connections, and sends and receives data. In
this example, the program will pass the server name to the AS400 object.</li>
<li id="guiex1__dup0042"><a name="guiex1__dup0042"><!-- --></a>The VJobList class is used by the IBM Toolbox for Java to represent a list of server jobs
that can be displayed in a vaccess (GUI) component. Notice that the AS400
object is used to specify the server on which the list resides.</li>
<li id="guiex1__dup0043"><a name="guiex1__dup0043"><!-- --></a>This line constructs a frame or a top-level window that will
be used to display the job list.</li>
<li id="guiex1__dup0044"><a name="guiex1__dup0044"><!-- --></a>ErrorDialogAdapter is an IBM Toolbox for Java graphical user interface (GUI) component
that is created to automatically display a dialog window whenever an error
event occurs in the application.</li>
<li id="guiex1__ten"><a name="guiex1__ten"><!-- --></a>This line creates an AS400ExplorerPane, a graphical user interface
(GUI) that represents a hierarchy of objects within a server resource. The
AS400ExplorerPane presents a tree on the left side rooted at the VJobList
and the details of the resource in the right side. This only initializes the
pane to a default state and does not load the contents of the VJobList to
the pane.</li>
<li id="guiex1__eleven"><a name="guiex1__eleven"><!-- --></a>This line adds the error handler you created in step nine
as a listener on the VJobList graphical user interface (GUI) component.</li>
<li id="guiex1__twelve"><a name="guiex1__twelve"><!-- --></a>This line loads the contents of the JobList into the ExplorerPane.
This method must be called explicitly to communicate to and load information
from the server. This gives the application control over when the communication
with the server will occur. With this you can: <ul><li>Load the contents before adding the pane to a frame. The frame does not
appear until all the information is loaded, as in this example.</li>
<li>Load the contents after adding the pane to a frame and displaying that
frame. The frame appears with a "wait cursor" and the information is filled
in as it is loaded.</li>
</ul>
</li>
<li id="guiex1__thirteen"><a name="guiex1__thirteen"><!-- --></a>This line adds a window listener so that the application
ends when the frame closes.</li>
<li id="guiex1__fourteen"><a name="guiex1__fourteen"><!-- --></a>This line adds the job list graphical user interface GUI
component to the center of the controlling frame.</li>
<li id="guiex1__fifteen"><a name="guiex1__fifteen"><!-- --></a>This line calls the show method to make the window visible
to the user.</li>
<li id="guiex1__sixteen"><a name="guiex1__sixteen"><!-- --></a>IBM Toolbox for Java exceptions are translated so the text
will appear in the language of the workstation. For example, this program
displays the text of the exception as its error processing.</li>
<li id="guiex1__seventeen"><a name="guiex1__seventeen"><!-- --></a>The IBM Toolbox for Java creates threads to carry out IBM Toolbox for Java activity.
If the program does not do System.exit(0) when it is terminated, the program
may not exit normally. For example, if the program was run from a Windows<sup>®</sup> 95
DOS prompt without this line, the command prompt does not return when the
program finished.</li>
</ol>
</div>
</div>
</body>
</html>