The command call vaccess (GUI) components allow a Java™ program to present a button or menu item that calls a non-interactive server command.
A CommandCallButton object represents a button that calls a server command when pressed. The CommandCallButton class extends the Java Foundation Classes (JFC) JButton class so that all buttons have a consistent appearance and behavior.
Similarly, a CommandCallMenuItem object represents a menu item that calls a server command when selected. The CommandCallMenuItem class extends the JFC JMenuItem class so that all menu items also have a consistent appearance and behavior.
To use a command call graphical user interface component, set both the system and command properties. These properties can be set using a constructor or through the setSystem() and setCommand() methods.
The following example creates a CommandCallButton. At run time, when the button is pressed, it creates a library called "FRED":
// Create the CommandCallButton // object. Assume that "system" is // an AS400 object created and // initialized elsewhere. The button // text says "Press Me", and there is // no icon. CommandCallButton button = new CommandCallButton ("Press Me", null, system); // Set the command that the button will run. button.setCommand ("CRTLIB FRED"); // Add the button to a frame. Assume // that "frame" is a JFrame created // elsewhere. frame.getContentPane ().add (button);
When a server command runs, it may return zero or more server messages. To detect when the server command runs, add an ActionCompletedListener to the button or menu item using the addActionCompletedListener() method. When the command runs, it fires an ActionCompletedEvent to all such listeners. A listener can use the getMessageList() method to retrieve any server messages that the command generated.
This example adds an ActionCompletedListener that processes all server messages that the command generated:
// Add an ActionCompletedListener that // is implemented using an anonymous // inner class. This is a convenient // way to specify simple event // listeners. button.addActionCompletedListener (new ActionCompletedListener () { public void actionCompleted (ActionCompletedEvent event) { // Cast the source of the event to a // CommandCallButton. CommandCallButton sourceButton = (CommandCallButton) event.getSource (); // Get the list of server messages // that the command generated. AS400Message[] messageList = sourceButton.getMessageList (); // ... Process the message list. } });Examples
This example shows how to use a CommandCallMenuItem in an application.
Figure 1 shows the CommandCall graphical user interface component:
Figure 1: CommandCall GUI component