ibm-information-center/dist/eclipse/plugins/i5OS.ic.rzahh_5.4.0.1/vprinterexample.htm

214 lines
7.4 KiB
HTML

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en-us" xml:lang="en-us">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="security" content="public" />
<meta name="Robots" content="index,follow" />
<meta http-equiv="PICS-Label" content='(PICS-1.1 "http://www.icra.org/ratingsv02.html" l gen true r (cz 1 lz 1 nz 1 oz 1 vz 1) "http://www.rsac.org/ratingsv01.html" l gen true r (n 0 s 0 v 0 l 0) "http://www.classify.org/safesurf/" l gen true r (SS~~000 1))' />
<meta name="DC.Type" content="reference" />
<meta name="DC.Title" content="Example: Using VPrinter" />
<meta name="abstract" content="" />
<meta name="description" content="" />
<meta name="copyright" content="(C) Copyright IBM Corporation 2006" />
<meta name="DC.Rights.Owner" content="(C) Copyright IBM Corporation 2006" />
<meta name="DC.Format" content="XHTML" />
<meta name="DC.Identifier" content="vprinterexample" />
<meta name="DC.Language" content="en-us" />
<!-- All rights reserved. Licensed Materials Property of IBM -->
<!-- US Government Users Restricted Rights -->
<!-- Use, duplication or disclosure restricted by -->
<!-- GSA ADP Schedule Contract with IBM Corp. -->
<link rel="stylesheet" type="text/css" href="./ibmdita.css" />
<link rel="stylesheet" type="text/css" href="./ic.css" />
<title>Example: Using VPrinter</title>
</head>
<body id="vprinterexample"><a name="vprinterexample"><!-- --></a>
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
<h1 class="topictitle1">Example: Using VPrinter</h1>
<div><p></p>
<div class="section"><div class="note"><span class="notetitle">Note:</span> Read the <a href="codedisclaimer.htm#codedisclaimer">Code
example disclaimer</a> for important legal information.</div>
</div>
<div class="section"><div class="p"><pre>//////////////////////////////////////////////////////////////////////////////////
//
// VPrinter example. This program presents a printer and its spooled
// files in an explorer pane.
//
// Command syntax:
// VPrinterExample system
//
//////////////////////////////////////////////////////////////////////////////////
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 &gt; 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);
}
}
}</pre>
</div>
</div>
<div class="section"><p><strong>Example: Using VPrinters</strong></p>
</div>
<div class="section"><div class="note"><span class="notetitle">Note:</span> Read the <a href="codedisclaimer.htm#codedisclaimer">Code
example disclaimer</a> for important legal information.</div>
</div>
<div class="section"><div class="p"><pre>/////////////////////////////////////////////////////////////////////////
//
// VPrinters example. This program presents various network
// print resources with an explorer pane.
//
// Command syntax:
// VPrintersExample system
//
// This source is an example of IBM Toolbox for Java "VPrinters".
//
/////////////////////////////////////////////////////////////////////////
import com.ibm.as400.access.*;
import com.ibm.as400.vaccess.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class VPrintersExample
{
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: VPrintersExample system");
return;
}
try
{
// Create an AS400 object. The system name was passed
// as the first command line argument.
AS400 system = new AS400 (args[0]);
// Create a VPrinters object which represents the list
// of printers attached to the system.
VPrinters printers = new VPrinters (system);
// Create a frame.
JFrame f = new JFrame ("VPrinters 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 network print resources.
// Use load to load the information from the system.
AS400ExplorerPane explorerPane = new AS400ExplorerPane (printers);
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);
}
}
}</pre>
</div>
</div>
</div>
</body>
</html>