[ Team LiB ] Previous Section Next Section

13.6 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.

Exercise 13-4. Modify your program from the previous exercise again to support "2-up" printing—printing two reduced-size pages side by side in landscape mode. You'll need to use Java 2D scaling and rotation features to accomplish this.

    [ Team LiB ] Previous Section Next Section