Java Reference
In-Depth Information
} if(this == printAction) {
// Get a printing object
if(printer == null) { // See if there is a
printer
JOptionPane.showMessageDialog(SketcherFrame.this,
"No default printer
available.",
"Printer Error",
JOptionPane.ERROR_MESSAGE);
return;
}
// The view is the page source
printJob.setPageable(theApp.getView());
boolean printIt = true;
// If it's not the toolbar button...
if(!(e.getSource() instanceof JButton)) {
printIt = printJob.printDialog();
// ...display the print
dialog
}
if(printIt) { // If printIt is
true...
try {
printJob.print(); // ...then print
} catch(PrinterException pe) {
System.err.println(pe);
JOptionPane.showMessageDialog(SketcherFrame.this,
"Error printing a sketch.",
"Printer Error",
JOptionPane.ERROR_MESSAGE);
}
}
} else if(this == exitAction) {
checkForSave();
System.exit(0);
}
Directory "Sketcher 12 using the Pageable interface"
This code is the earlier version that uses the printDialog() method without an argument to show the
effect in this context. If you comment out the most recent code, you can try both versions by juggling the
commented-out code. On my system, the print dialog now shows that pages numbered from 1 to 2 should
be printed, courtesy of the Pageable interface implementation that you added to Sketcher. You can see
my print dialog in Figure 21-15 .
FIGURE 21-15
 
 
Search WWH ::




Custom Search