Java Reference
In-Depth Information
PrintRequestAttributeSet attrs = new
new HashPrintRequestAttributeSet ();
attrs . add ( OrientationRequested . LANDSCAPE );
attrs . add ( MediaSizeName . NA_LETTER );
attrs . add ( new
new Copies ( 1 ));
attrs . add ( new
new JobName ( INPUT_FILE_NAME , null
null ));
InputStream is = getClass (). getResourceAsStream ( INPUT_FILE_NAME );
iif ( is == null
null ) {
throw
throw new
new NullPointerException (
"Input Stream is null: file not found?" );
}
Doc doc = new
new SimpleDoc ( is , inputFlavor , null
null );
DocPrintJob printJob = printService . createPrintJob ();
printJob . print ( doc , attrs );
}
}
See Also
The Printing API has other useful methods described in the documentation, which you can
also find at Oracle's website .
Program: PlotterAWT
In Program: Plotter , we discussed a series of Plotter classes. The PlotterAWT class shown
in Example 12-12 extends that recipe to provide a “plot preview” service: before being plot-
ted on a (probably slow) plotter, the plot is displayed in an AWT window using the Graphics
drawing primitives.
Example 12-12. PlotterAWT.java
public
public class
class PlotterAWT
PlotterAWT extends
extends Plotter {
private
private JFrame f ;
private
private PCanvas p ;
private
private Graphics g ;
private
private Font font ;
private
private FontMetrics fontMetrics ;
PlotterAWT () {
f = new
new JFrame ( "Plotter" );
Container cp = f . getContentPane ();
Search WWH ::




Custom Search