// Java 1.1 used java.awt.PrintJob.
// In Java 1.2 we use java.awt.print.PrinterJob
PrinterJob job = PrinterJob.getPrinterJob();
// Alter the default page settings to request landscape mode
PageFormat page = job.defaultPage();
page.setOrientation(PageFormat.LANDSCAPE); // landscape by default
// Tell the PrinterJob what Printable object we want to print.
// PrintableComponent is defined as an inner class below
String title = "Julia set for c={" + cx + "," + cy + "}";
Printable printable = new PrintableComponent(this, title);
job.setPrintable(printable, page);
// Call the printDialog() method to give the user a chance to alter
// the printing attributes or to cancel the printing request.
if (job.printDialog()) {
// If we get here, then the user did not cancel the print job
// So start printing, displaying a dialog for errors.
try { job.print(); }
catch(PrinterException e) {
JOptionPane.showMessageDialog(this, e.toString(),
"PrinterException",
JOptionPane.ERROR_MESSAGE);
}
}