VPrinter Example
////////////////////////////////////////////////////////////////////////
//
// VPrinter example. This program presents a printer and its spooled
// files in an explorer pane.
//
// Command syntax:
// VPrinterExample system
//
/////////////////////////////////////////////////////////////////////////
//
// This source is an example of AS/400 Toolbox for Java "VPrinter".
// IBM grants you a nonexclusive license to use this as an example
// from which you can generate similar function tailored to
// your own specific needs.
//
// This sample code is provided by IBM for illustrative purposes
// only. These examples have not been thoroughly tested under all
// conditions. IBM, therefore, cannot guarantee or imply
// reliability, serviceability, or function of these programs.
//
// All programs contained herein are provided to you "AS IS"
// without any warranties of any kind. The implied warranties of
// merchantablility and fitness for a particular purpose are
// expressly disclaimed.
//
// AS/400 Toolbox for Java
// (C) Copyright IBM Corp. 1997, 1998
// All rights reserved.
// US Government Users Restricted Rights -
// Use, duplication, or disclosure restricted
// by GSA ADP Schedule Contract with IBM Corp.
//
/////////////////////////////////////////////////////////////////////////
import com.ibm.as400.access.*;
import com.ibm.as400.vaccess.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class VPrinterExample
{
public static void main (String[] args)
{
// If the user does not supply a printer name then show printer information
// for a printer called OS2VPRT;
String printerName = "OS2VPRT";
// If a system was not specified, then display help text and
// exit.
if (args.length == 0)
{
System.out.println("Usage: VPrinterExample system printer");
return;
}
// If the user specified a name, use it instead of the default.
if (args.length > 1)
printerName = args[1];
try
{
// Create an AS400 object. The system name was passed
// as the first command line argument.
AS400 system = new AS400 (args[0]);
// Create a Printer object (from the Toolbox access package)
// which represents the printer, then create a VPrinter
// object to graphically show the spooled files on the printer.
Printer printer = new Printer(system, printerName);
VPrinter vprinter = new VPrinter(printer);
// Create a frame to hold our window.
JFrame f = new JFrame ("VPrinter 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 printer and its spooled
// files. Use load to load the information from the system.
AS400ExplorerPane explorerPane = new AS400ExplorerPane (vprinter);
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);
}
}
}