Now that you know about the different classes necessary to print, let's put it all together. Printing takes four steps:
PrintJob pjob = getToolkit().getPrintJob(this, "Job Title", (Properties)null);
Graphics pg = pjob.getGraphics();
printAll(pg); pg.dispose(); // This is like sending a form feed
pjob.end();
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.
This HTML Help has been published using the chm2web software. |