Command CallThe command call graphical user interface components allow a Java program to present a button or menu item that calls a non-interactive AS/400 command. A CommandCallButton object represents a button that calls an AS/400 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 an AS/400 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 an AS/400 command runs, it may return zero or more AS/400 messages. To detect when the AS/400 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 AS/400 messages that the command generated. This example adds an ActionCompletedListener that processes all AS/400 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 AS/400 messages // that the command generated. AS400Message[] messageList = sourceButton.getMessageList (); // ... Process the message list. } });
ExamplesThis example shows how to use a CommandCallMenuItem in an application. The image below shows the CommandCall graphical user interface component:
[ Legal | AS/400 Glossary ] |