FileDocCategorySizeDatePackage
PrintDemo0.javaAPI DocExample1472Sat Nov 25 12:55:08 GMT 2000None

PrintDemo0

public class PrintDemo0 extends Frame
PrintDemo0 -- Print Demo Program - JDK1.1 Version Prints three pages (or so).

Fields Summary
protected static final int
NPAGES
Constructors Summary
Methods Summary
public static voidmain(java.lang.String[] av)
main program: instantiate and run.


	      
	     
		PrintDemo0 pd = new PrintDemo0();
		pd.setVisible(true);
		pd.print(NPAGES);
	
public voidprint(int nPages)

		PrintJob pjob = null;	// refers to whole print job
		Graphics pg = null;	// refers to current page

		System.out.println("Getting PrintJob");
		pjob = getToolkit().getPrintJob(this,
			"Printing Test", (Properties)null);
		if (pjob == null)          // User cancelled??
			return;

		// Just get and show dimensions; should use in x,y calcs.
		Dimension pDim = pjob.getPageDimension();
		int pRes = pjob.getPageResolution();
		System.out.println("Page size " + pDim + "; Res " + pRes);

		// Print up to "np" number of pages
		for (int pgNum=1; pgNum<=nPages; pgNum++) {
			System.out.println("Starting page # " + pgNum);
			pg = pjob.getGraphics();
			if (pg == null) 	// ??
				return;
			pg.setColor(Color.black);
			pg.setFont(new Font("Times", Font.PLAIN, 12));
			pg.drawString("Hello World", 100, 100);
			pg.drawString("Page" + pgNum, 300, 300);
			pg.dispose(); // flush page
			System.out.println("All done with page " + pgNum);
		}
		pjob.end();	// total end of print job.
		pjob = null;	// avoid redundant calls to pjob.end()
		return;