17.4 Printing ExampleNow that you know about the different classes necessary to print, let's put it all together. Printing takes four steps:
The following code summarizes how to print:
// Java 1.1 only PrintJob pjob = getToolkit().getPrintJob(this, "Print?", (Properties)null); if (pjob != null) { Graphics pg = pjob.getGraphics(); if (pg != null) { printAll(pg); pg.dispose(); } pjob.end(); } This code prints the current component: what you get from the printer should be a reasonable rendition of what you see on the screen. Note that we didn't need to modify paint() at all. That should always be the case if you want your printer output to look like your onscreen component. |
|