Printing

Java 1.1 implements printing through the java.awt.PrintGraphics interface and the abstract java.awt.Printjob class.

To begin a print job you call the static method Toolkit.getPrintJob(). This returns a platform specific instance of the abstract PrintJob class. (Platform specific details are hidden inside the sun classes.)

The PrintJob object gives you information about the page size and the printer resolution. It also has a getGraphics() method that returns a Graphics object that implements the PrintGraphics interface. Often you'll draw the page by passing this object to your paint() method. Other times you'll want to specialize for printing. For example, you might want to draw in black and white instead of color. (Regrettably Java does not provide a method to determine the available colors on the printer.)

A page is sent to the printer when you invoke its Graphics's object's dispose() method. You can print multiple pages by repeatedly calling getGraphics() and the disposing each Graphics object.


Previous | Next | Top
Last Modified April 19, 1997
Copyright 1997 Elliotte Rusty Harold
elharo@metalab.unc.edu