17.2 PrintJob ClassThe abstract PrintJob class provides the basis for the platform-specific printing subclasses. Through PrintJob, you have access to properties like page size and resolution. Constructor and Pseudo-Constructor
Since you can't call the PrintJob constructor directly, you need some other way of getting a print job to work with. The proper way to get an instance of PrintJob is to ask the Toolkit, which is described in Chapter 15, Toolkit and Peers. The getPrintJob() method requires a Frame as the first parameter, a String as the second parameter, and a Properties set as the third parameter. Here's how you might call it:
PrintJob pjob = getToolkit().getPrintJob(aFrame, "Job Title", (Properties)null); The Frame is used to hold a print dialog box, asking the user to confirm or cancel the print job. (Whether or not you get the print dialog may be platform specific, but your programs should always assume that the dialog may appear.) The String is the job's title; it will be used to identify the job in the print queue and on the job's header page, if there is one. The Properties parameter is used to request printing options, like page reversal. The property names, and whether the requested properties are honored at all, are platform specific. UNIX systems use the following properties:
awt.print.printer Windows NT/95 ignores the properties sheet. If the properties sheet is null, as in the previous example, you get the system's default printing options. If the properties sheet is non-null, getPrintJob() modifies it to show the actual options used to print the job. You can use the modified properties sheet to find out what properties are recognized on your system and to save a set of printing options for use on a later print job. If you are printing multiple pages, each page should originate from the same print job. According to Sun's documentation, getPrintJob() ought to return null if the user cancels the print job. However, this is a problem. On some platforms (notably Windows NT/95), the print dialog box doesn't even appear until you call the getGraphics() method. In this case, getPrintJob() still returns a print job and never returns null. If the user cancels the job, getGraphics() returns null. Methods
|
|