Java Reference
In-Depth Information
First the program invokes the method
PrintJob getPrintJob (Frame frame, String title, Properties
props)
from the AWT toolkit. This displays the system print dialog on the screen. The first
parameter in getPrintJob() references the frame to which the print dialog
belongs. The title string, which appears on the top bar of the print dialog, comes
next. The last parameter is a reference to a Properties object, which we set
to null in this example. The properties were never standardized so they are not
portable. With Java 1.3 came the overloaded method
PrintJob getPrintJob (Frame f, String t, JobAttributes
jA, PageAttributes pA)
Here the parameters include instances of the JobAttributes and PageAt-
tributes classes. These classes provide methods to set a wide range of printer
control parameters such as the number of copies, the page ranges, paper size,
orientation, and so forth.
The standard printer dialog for the local platform appears after the invocation
of the getPrintJob() method. The returned PrintJob object provides an
instance of PrintGraphics via the getGraphics() method. This object,
which is a subclass of Graphics ,isthen passed to the paint() or paint-
Component() method, which proceeds to paint the frame display for the printer
output.
As discussed in Section 6.6.2, a ratio of 72 user units to 1 inch is maintained for
drawing commands regardless of the printer's resolution setting. If there are sub-
components on the frame, such as buttons and labels, these also paint themselves
to the printer.
12.3 Cursor icons
It can be useful when designing a user interface to alter the appearance of the
cursor according to the current position and/or processing going on. The AWT
has the Cursor class that comes with 14 different cursor icons. The Component
class includes the setCursor() method that can change the cursor icon when
it lies above a particular component.
In the following code snippet we show the class CursorPanel ,which extends
JPanel .Onthe panel we add a 7
2grid of buttons and for each button we
use the setCursor() method to set to an instance of a Cursor class. The
particular type of cursor depends on the value of the constant in that class such
as Cursor.WAIT - CURSOR passed in the Cursor constructor. See the applet
CursorTestApplet in the Web Course Chapter 12 for a demonstration of this
panel.
×
Search WWH ::




Custom Search