Вы находитесь на странице: 1из 4

GUI Example 1 of 1

Use the following as an example for your program.

// Example using the IBM Toolbox for Java's Graphical User Interface
// class, VJobList.
// This source is an example of IBM Toolbox for Java "Job List".
// IBM grants you a nonexclusive license to use this as an example
// from which you can generate similar function tailored to
// your own specific needs.
// This sample code is provided by IBM for illustrative purposes
// only. These examples have not been thoroughly tested under all
// conditions. IBM, therefore, cannot guarantee or imply
// reliability, serviceability, or function of these programs.
// All programs contained herein are provided to you "AS IS"
// without any warranties of any kind. The implied warranties of
// merchantability and fitness for a particular purpose are
// expressly disclaimed.
// IBM Toolbox for Java
// (C) Copyright IBM Corp. 1999
// All rights reserved.
// US Government Users Restricted Rights // Use, duplication, or disclosure restricted
// by GSA ADP Schedule Contract with IBM Corp.
package examples;1
import com.ibm.as400.access.*;
import com.ibm.as400.vaccess.*;

import javax.swing.*;3
import java.awt.*;
import java.awt.event.*;
public class GUIExample
public static void main(String[] parameters)4
GUIExample example = new GUIExample(parameters);

public GUIExample(String[] parameters)

try 5
// Create an AS400 object.
//The system name was passed as the first command line argument.
AS400 system = new AS400 (parameters[0]);6
VJobList jobList = new VJobList (system);7
// Create a frame.
JFrame frame = new JFrame ("Job List Example");

// Create an error dialog adapter. This will display any errors to

the user.
ErrorDialogAdapter errorHandler = new ErrorDialogAdapter (frame);9
// Create an explorer pane to present the job list.
AS400ExplorerPane explorerPane = new AS400ExplorerPane (jobList);10
explorerPane.addErrorListener (errorHandler);11
// Use load to load the information from the system.
// When the frame closes, exit the program.
frame.addWindowListener (new WindowAdapter () 13
public void windowClosing (WindowEvent event)
} );
// Layout the frame with the explorer pane.
frame.getContentPane().setLayout(new BorderLayout() );
frame.getContentPane().add("Center", explorerPane);


catch (Exception e)

1. This class is in the examples package. Java uses packages to avoid name
conflicts between Java class files.

2. This line makes all of the IBM 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.
3. 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 graphical user interface (GUI) classes need JDK 1.1.2 plus Java
Swing 1.0.3 from Sun Microsystems, Inc. Swing is available with Sun's JFC
4. 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 AS/400. Either the jt400.zip or jt400.jar
must be in your classpath for this to work.
5. The IBM Toolbox for Java code throws exceptions that your program must
6. 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 AS/400 system name
to the AS400 object.
7. The VJobList class is used by the IBM Toolbox for Java to represent a list of
AS/400 jobs that can be displayed in a graphical user interface (GUI)
component. Notice that the AS400 object is used to specify the AS/400 on
which the list resides.
8. This line constructs a frame or a top-level window that will be used to display
the job list.
9. 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.
10. This line creates an AS400ExplorerPane, a graphical user interface (GUI)
that represents a hierarchy of objects within an AS/400 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.
11. This line adds the error handler you created in step nine as a listener on the
VJobList graphical user interface (GUI) component.
12. 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 AS/400. This gives the application control over when the
communication with the AS/400 will occur. With this you can:
o Load the contents before adding the pane to a frame. The frame does
not appear until all the information is loaded (This example).
o 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.

13. This line adds a window listener so that the application ends when the frame
14. This line adds the job list graphical user interface GUI component to the
center of the controlling frame.
15. This line calls the show method to make the window visible to the user.
16. 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.
17. 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 95 DOS prompt without this line, the command prompt would not
return when the program finished.