///////////////////////////////////////////////////////////////////////// // // Message queue example. This program presents a message queue in an // explorer pane. // // Command syntax: // VMessageQueueExample system // // This source is an example of IBM Toolbox for Java "VMessageQueue". // ///////////////////////////////////////////////////////////////////////// import com.ibm.as400.access.*; import com.ibm.as400.vaccess.*; import javax.swing.*; import java.awt.*; import java.awt.event.*; public class VMessageQueueExample { public static void main (String[] args) { // If a system was not specified, then display help text and // exit. if (args.length != 1) { System.out.println("Usage: VMessageQueueExample system"); return; } try { // Create an AS400 object. The system name was passed // as the first command line argument. AS400 system = new AS400 (args[0]); // Force the user to sign on so that we know the user id. system.connectService (AS400.COMMAND); // Create a VMessageQueue object which represents the // current user's message queue. VMessageQueue queue = new VMessageQueue (system, QSYSObjectPathName.toPath ("QUSRSYS", system.getUserId (), "MSGQ")); // Create a frame. JFrame f = new JFrame ("Message queue example"); // Create an error dialog adapter. This will display // any errors to the user. ErrorDialogAdapter errorHandler = new ErrorDialogAdapter (f); // Create an explorer pane to present the message queue. // Use load to load the information from the system. AS400ExplorerPane explorerPane = new AS400ExplorerPane (queue); explorerPane.addErrorListener (errorHandler); explorerPane.load (); // When the frame closes, exit. f.addWindowListener (new WindowAdapter () { public void windowClosing (WindowEvent event) { System.exit (0); } }); // Layout the frame with the explorer pane. f.getContentPane ().setLayout (new BorderLayout ()); f.getContentPane ().add ("Center", explorerPane); f.pack (); f.show (); } catch (Exception e) { System.out.println ("Error: " + e.getMessage ()); System.exit (0); } } }