|
The iSeries Toolbox for Java: GUI-izing Program Calls
by Kevin Vandever
[The code for this article is available for download.]
In "Learning Java
by Example," Shannon O'Donnell provided some simple Java applications that allowed you to execute
PC commands and access spool files from the iSeries. He did this to arm you with new tools, but he also
afforded you working code from which you could learn Java. Using the same premise, in this article I will
provide you with a Java application to call an iSeries program and display the results on a GUI form.
Download it and use it as is, or mold it to fit your needs.
Another Way to Call a Program
If you've read my articles on the iSeries Toolbox for Java, you know that I have written about a couple of
different ways to call iSeries programs from Java. In fact, I have written about my two preferred methods,
using the toolbox and another method that doesn't use the toolbox at all. I am about to show you another
way to call iSeries programs from Java, but this isn't necessarily a method that you will use in a production
environment, as you would with my previous examples. This method will most likely be used as a tool by
you or maybe others within your shop. But, hey, don't let me limit you; use it as you see fit.
System Status with a Click of a Button
This application will call the system API, QWCRSSTS, which returns system status information, and
display some of that information in an applet (GUI screen). The Java source for this application can be
found in the ProgramCallButtonExample.java file. Instructions for downloading
the iSeries Toolkit for Java and properly setting up your environment can be found in "Calling a Program Using the
iSeries Toolbox for Java."
This code is provided by IBM as an example of how to
display the results of a program call in a Java applet. I have used this code as is, but have also modified it to
display results from homegrown iSeries programs. Follow the same structure of this program, and you'll be
set.
Description of the Code
You will notice two main methods, one static and the other non-static. The static method creates an
instance of the ProgramCallButtonExample class and calls the non-static Main method, which accepts the
input parameters and performs the rest of the logic.
This demo application accepts a system name or IP address for the AS/400 you want to connect to. If you
forget this parameter, it will tell you. The code within the Try block then builds the GUI applet, creates an
AS/400 connection object based on the input parameter you supply, and then creates a program path object
based on the program you are going to call and on, of course, the path where it resides.
The Java program then sets up the parameters required for the specific API. You will notice some Java-to-
AS/400 conversion classes being used to set up the parameters. Java integers, BigDecimals, and Strings
have to be converted to their iSeries counterparts before they can be used. I won't cover these in too much
detail because they really aren't used anymore, except in this technique, because there have been new ways
invented to convert Java data to iSeries data that are much easier to use. (See my previous articles on calling programs
from Java for more details on these techniques.)
After the parameters are set, the Java application handles what happens when the user closes the applet
window (in this case it exits nicely) and what happens when the user clicks the Refresh button (in this case,
it makes a call to the AS/400 API).
Give It a Try
Java applets are not used all that much anymore, as they have made way for more server-side solutions
such as servlets and JavaServer Pages. However, as a tool to use internally, or as a way to learn Java from a
working example, this technique works quite well. Enjoy!
|