Java Reference
In-Depth Information
return NO _ SUCH _ PAGE;
Graphics2D g2D = (Graphics2D) g;
// Move origin to page printing area corner
g2D.translate(pageFormat.getImageableX(), pageFormat.getImageableY());
paint(g2D); // Draw the sketch
return PAGE _ EXISTS;
}
The translate() method call moves the user coordinate system so that the (0,0) point is positioned at
the top left corner on the printable area on the page.
Let's see if that works in practice.
Try It Out - Printing a Sketch
You should have added the code we saw earlier to the actionPerformed() method to handle the
Print menu item event, and the code to SketchView to implement the Printable interface that we
have evolved. Don't forget the import statement for java.awt.print . If you compile and run
Sketcher, you should be able to print a sketch.
On my system, when I select the toolbar button to print, I get the dialog shown below.
This is the standard dialog for my printer under Windows. In your environment you will get a dialog for
your default printer. The reason the dialog indicates that there are 9999 pages to be printed is that we
haven't said how many, so the maximum is being assumed.
Search WWH ::




Custom Search