Академический Документы
Профессиональный Документы
Культура Документы
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);
}
14
frame.pack();
frame.show();15
}
catch (Exception e)
{
e.printStackTrace();16
System.exit(0);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 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
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 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
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 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
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 would not
return when the program finished.