Data queues

The data queue graphical components allow a Java™ program to use any Java Foundation Classes (JFC) graphical text component to read or write to a server data queue.

The DataQueueDocument and KeyedDataQueueDocument classes are implementations of the JFC Document interface. These classes can be used directly with any JFC graphical text component. Several text components, such as single line fields (JTextField) and multiple line text areas (JTextArea), are available in JFC.

Data queue documents associate the contents of a text component with a server data queue. (A text component is a graphical component used to display text that the user can optionally edit.) The Java program can read and write between the text component and data queue at any time. Use DataQueueDocument for sequential data queues and KeyedDataQueueDocument for keyed data queues.

To use a DataQueueDocument, set both the system and path properties. These properties can be set using a constructor or through the setSystem() and setPath() methods. The DataQueueDocument object is then "plugged" into the text component, usually using the text component's constructor or setDocument() method. KeyedDataQueueDocuments work the same way.

The following example creates a DataQueueDocument whose contents are associated with a data queue:

                       // Create the DataQueueDocument
                       // object. Assume that "system" is
                       // an AS400 object created and 
                       // initialized elsewhere. 
     DataQueueDocument dqDocument = new DataQueueDocument (system, "/QSYS.LIB/MYLIB.LIB/MYQUEUE.DTAQ");

                       // Create a text area to present the
                       // document.
     JTextArea textArea = new JTextArea (dqDocument);

                       // Add the text area to a frame.
                       // Assume that "frame" is a JFrame
                       // created elsewhere.
     frame.getContentPane ().add (textArea);

Initially, the contents of the text component are empty. Use read() or peek() to fill the contents with the next entry on the queue. Use write() to write the contents of the text component to the data queue. Note that these documents only work with String data queue entries.

Examples

Example of using a DataQueueDocument in an application.

Figure 1 shows the DataQueueDocument graphical user interface component being used in a JTextField. A button has been added to provide a GUI interface for the user to write the contents of the test field to the data queue.

Figure 1: DataQueueDocument GUI component

DataQueueDocument GUI component