Posted By:
Michael_Wax
Posted On:
Sunday, April 8, 2001 01:09 PM
Basic printing under the AWT works like the following:
Toolkit toolkit = Toolkit.getDefaultToolkit();
PrintJob job = toolkit.getPrintJob(parentFrame, jobTitle, jobProperties);
if (job != null) {
//only come here if the user hasn't cancelled the print dialog
Graphics pg = job.getGraphics();
if (pg != null) {
paint(pg);
pg.dispose();
}
job.end();
}
The fields and methods used above are:
- Frame parentFrame - the parent frame of the print dialog
- String jobTitle - the name of the print job
- Properties jobProperties - a properties file with information on the print job, e.g., number of copies
- paint - could be the same paint method used for display, or could be a different, print-specific method
You probably will need to play with this to make it work optimally, as differences in what you are printing, and the system and printer that you are using, tend to affect the output. In particular, you may need to modify the paint method to ensure that the printed version looks good.