Java Reference
In-Depth Information
statement that follows the first if statement that creates the pageFormat object. These are all taken care of
elsewhere now. You can also remove the statements that set the page orientation, because this is dealt with
by the page dialog that is displayed when the “Print Setup...” menu item is clicked. The code now looks like
this:
} 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;
}
printJob.setPrintable(theApp.getView(), pageFormat);
boolean printIt = true;
// If it's not a 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 10 with printer page setup"
On my system, the pageDialog() method displays the dialog shown in Figure 21-12 .
FIGURE 21-12
 
 
Search WWH ::




Custom Search