Most read:
Popular archives:
JavaWorld's new look is here!
We've upgraded the site with a fresh look-and-feel, improved topical navigation, better search, new features, and expanded
community platform. Learn more about the changes to JavaWorld.
| Oracle Compatibility Developer's Guide |
| The Explosion in DBMS Choice |
This month, we'll add Java 2 print capabilities to our old pal, the Swing Forum. But first we'll investigate the basics of the Java 2 printing system, including its operating principles and high-level features.
The Java 2 printing system offers applications the ability to print AWT text and graphics to any standard printer, whether networked or local. The printing system is a "callback" system, which means the system, not the printing application, drives the print process. In practice, this means the system determines the order in which pages are printed and makes callbacks into programmer-defined objects that know how to print pages. This architecture is similar to the 1.1 delegation event model and is highly analogous to the way component painting works.
The printing system consists of two entity types: job-control entities, which control printer jobs, and document-related entities,
which represent documents to be printed as well as their constituent pages. The printing API is contained in the package java.awt.print.
Note: The Java 2 printing system should not be confused with the 1.1 printing system, although it is similar in some respects.
Classes PrinterJob, PageFormat, and Paper are the job-control entities responsible for printer-job management.
The PrinterJob class encapsulates a printer job. PrinterJob operations include retrieving the default page format, popping up print- and page-format dialogs, and printing the job.
The PageFormat class represents a set of page-format settings. This class provides offset- and imageable-area information for use in rendering
pages.
The Paper class represents the physical properties of a piece of paper in the printer. This class is used by the system and is not
necessary for applications development.
In addition to the job-control entities described above, Java 2 printing makes use of document-related entities that provide both high level and low level document printing services, which we'll look at next.
Document-related entities can be classified as either high level or low level. Pageable and Book are considered high level. In contrast, Printable "page painters" are low level.
High-level document-related entities represent whole documents, such as a resume, a book, or any other collection of printable pages.
A document is a collection of pages in which each page or group of pages may have different formats. For example, a business letter might consist of a "first page" that displays letterhead and standard header information and the beginning of the letter's text. This page may be followed by a series of additional pages containing the rest of the letter's text.