Exercises

  • Exercise 13-1. In Java 1.3, java.awt.JobAttributes and java.awt.PageAttributes are new classes that enhance the Java 1.1 Printing API. Read the documentation for these classes, then modify the HardcopyWriter class so that you can pass PageAttributes and JobAttributes objects to the HardcopyWriter 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 a Printable 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 the HardcopyWriter 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 the Pageable interface. Otherwise, if you paginate as you print, you’ll have to implement the Printable interface. In either case, you should be able to reuse code from HardcopyWriter.

  • Exercise 13-3. Modify your program from the previous example so that the Printable or Pageable object you implemented is printed with a Java 1.4 javax.print.PrintService object instead of a Java 1.2 java.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.