Printing with the Java 1.2 API
Example 13-2
is a listing of JuliaSet2
. This
subclass of Example 13-1
displays a different Julia set (pictured in Figure 13-2) and overrides the
print( )
method, to demonstrate
printing out the set using the Java 1.2 API. Like its superclass,
JuliaSet2
should be tested using
the ShowBean
program.
Figure 13-2. A Julia set printed with the Java 1.2 API
The key to this example is the inner class PrintableComponent
, which implements the java.awt.print.Printable
interface to print
a component and a title for that component. Pay attention to the
return value of the Printable.print(
)
method: the Printable
interface can represent multipage documents, and uses its return value
to tell the printing system when the last page of the document has
been reached.
The java.awt.print
package
also defines an interface named Pageable
, which is useful for defining multipage documents for
which the number of pages is known in advance. It allows different
pages of the document to be printed using different PageFormat
objects, which allows for
different margins, orientations, and so forth. Pageable
documents are not demonstrated in
this chapter.
Example 13-2. JuliaSet2.java
package je3.print; import javax.swing.*; import java.awt.*; import java.awt.print.*; // This package is the Java 1.2 printing API /** * This class extends JuliaSet1 and overrides the print( ) method to ...
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.