Java Reference
In-Depth Information
How It Works
The code in the actionPerformed() method displays the print dialog by calling the
printDialog() method for the PrinterJob object that we obtain. Clicking on the OK button
causes the print() method for the PrinterJob object to be called. This in turn causes the print()
method in the SketchView class to be called once for each page to be printed, and one more time to
end the process.
In the print() method in SketchView , we adjust the origin of the user coordinate system for the
graphics context so that its position is at the top left corner of the printable area on the page. Only one
page is printed because we return NO _ SUCH _ PAGE when the page index value that is passed to the
print() method is greater than 0. Incidentally, if you want to see how many times the print()
method gets called for a page, just add a statement at the beginning of the method to output some trace
information to the console.
I used the print facility to print the
sketch shown here, and frankly, I was
disappointed.
The picture that I get printed on the
paper is shown here. There's only one
flower in view, and that interesting
cross between a rabbit and a cat is
completely missing.
Search WWH ::




Custom Search