Example: Displaying a list of server jobs in a GUI

Use the following as an example for your program.

Note: Read the Code example disclaimer for important legal information.
//////////////////////////////////////////////////////////////////////////////////
//
// 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;  Note 1 

import com.ibm.as400.access.*;
import com.ibm.as400.vaccess.*;  Note 2 

import javax.swing.*;  Note 3 
import java.awt.*;
import java.awt.event.*;

public class GUIExample
{

  public static void main(String[] parameters)  Note 4 
  {
     GUIExample example = new GUIExample(parameters);

  }

  public GUIExample(String[] parameters)
  {
     try  Note 5 
     {
          // Create an AS400 object.
     //The system name was passed as the first command line argument.
          AS400 system = new AS400 (parameters[0]);  Note 6 
          
          VJobList jobList = new VJobList (system);  Note 7 

     // Create a frame.
     JFrame frame = new JFrame ("Job List Example");  Note 8 

     // Create an error dialog adapter.  This will display any errors to the user.
     ErrorDialogAdapter errorHandler = new ErrorDialogAdapter (frame);  Note 9 

     // Create an explorer pane to present the job list.
     AS400ExplorerPane explorerPane = new AS400ExplorerPane (jobList);  Note 10 
     
     explorerPane.addErrorListener (errorHandler);  Note 11 

     // Use load to load the information from the system.   
     explorerPane.load();  Note 12 

     // When the frame closes, exit the program.
     frame.addWindowListener (new WindowAdapter ()  Note 13 
     {
           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);  Note 14 

     frame.pack();
     frame.show();  Note 15 
     }

     catch (Exception e)
     {
          e.printStackTrace();  Note 16 
     }
     System.exit(0);  Note 17 

     }
}
  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 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.
  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 server. 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 catch.
  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 server name to the AS400 object.
  7. 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.
  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 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.
  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 server. This gives the application control over when the communication with the server will occur. With this you can:
    • 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.
    • 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 closes.
  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 does not return when the program finished.