Exercises
Exercise 13-1. In Java 1.3,
java.awt.JobAttributes
andjava.awt.PageAttributes
are new classes that enhance the Java 1.1 Printing API. Read the documentation for these classes, then modify theHardcopyWriter
class so that you can passPageAttributes
andJobAttributes
objects to theHardcopyWriter
constructor. Test your modification by writing a program that prints in landscape mode and uses duplex (two-sided) printing (if you have a printer that supports this feature).Exercise 13-2. With the Java 1.2 Printing API, the
print( )
method of aPrintable
object may be called multiple times per page to facilitate the printing of high-resolution images and drawings. For this reason, it is not possible to print a character stream with the Java 1.2 API, as is done with the Java 1.1 API in theHardcopyWriter
class. Nevertheless, it is still possible to print multipage text documents using the Java 1.2 API. Write a program that reads a plain text file, paginates it, and prints its contents using the Java 1.2 API. If you paginate the entire document in an initial pass, then you can implement thePageable
interface. Otherwise, if you paginate as you print, you’ll have to implement thePrintable
interface. In either case, you should be able to reuse code fromHardcopyWriter
.Exercise 13-3. Modify your program from the previous example so that the
Printable
orPageable
object you implemented is printed with a Java 1.4javax.print.PrintService
object instead of a Java 1.2java.print.PrinterJob ...
Get Java Examples in a Nutshell, 3rd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.