List of usage examples for java.awt Toolkit getPrintJob
public PrintJob getPrintJob(Frame frame, String jobtitle, JobAttributes jobAttributes,
PageAttributes pageAttributes)
From source file:JuliaSet2.java
public void print() { // Create some attributes objects. This is Java 1.3 stuff. // In Java 1.1, we'd use a java.util.Preferences object instead. JobAttributes jattrs = new JobAttributes(); PageAttributes pattrs = new PageAttributes(); // Set some example attributes: monochrome, landscape mode pattrs.setColor(PageAttributes.ColorType.MONOCHROME); pattrs.setOrientationRequested(PageAttributes.OrientationRequestedType.LANDSCAPE); // Print to file by default jattrs.setDestination(JobAttributes.DestinationType.FILE); jattrs.setFileName("juliaset.ps"); // Look up the Frame that holds this component Component frame = this; while (!(frame instanceof Frame)) frame = frame.getParent();// ww w. ja va 2s .c om // Get a PrintJob object to print the Julia set with. // The getPrintJob() method displays a print dialog and allows the user // to override and modify the default JobAttributes and PageAttributes Toolkit toolkit = this.getToolkit(); PrintJob job = toolkit.getPrintJob((Frame) frame, "JuliaSet1", jattrs, pattrs); // We get a null PrintJob if the user clicked cancel if (job == null) return; // Get a Graphics object from the PrintJob. // We print simply by drawing to this Graphics object. Graphics g = job.getGraphics(); // Center the image on the page Dimension pagesize = job.getPageDimension(); // how big is page? Dimension panesize = this.getSize(); // how big is image? g.translate((pagesize.width - panesize.width) / 2, // center it (pagesize.height - panesize.height) / 2); // Draw a box around the Julia Set and label it g.drawRect(-1, -1, panesize.width + 2, panesize.height + 2); g.drawString("Julia Set for c={" + cx + "," + cy + "}", 0, -15); // Set a clipping region g.setClip(0, 0, panesize.width, panesize.height); // Now print the component by calling its paint method this.paint(g); // Finally tell the printer we're done with the page. // No output will be generated if we don't call dispose() here. g.dispose(); }