implements Printable : Print « 2D Graphics « Java Tutorial






import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.print.PageFormat;
import java.awt.print.Printable;
import java.awt.print.PrinterException;
import java.awt.print.PrinterJob;

public class Main implements Printable {
  private static Font sFont = new Font("Serif", Font.PLAIN, 64);

  public int print(Graphics g, PageFormat Pf, int pageIndex) throws PrinterException {
    if (pageIndex > 0)
      return NO_SUCH_PAGE;
    Graphics2D g2 = (Graphics2D) g;
    g2.setFont(sFont);
    g2.setPaint(Color.black);
    g2.drawString("Save a tree!", 96, 144);
    return PAGE_EXISTS;
  }

  public static void main(String[] args) {
    PrinterJob job = PrinterJob.getPrinterJob();
    job.setPrintable(new Main());
    if (job.printDialog()) {
      try {
        job.print();
      } catch (PrinterException e) {
      }
    }
    System.exit(0);
  }
}








16.50.Print
16.50.1.implements Printable
16.50.2.Print an image out
16.50.3.javax.print API and allows you to list available printers, query a named printer, print text and image files to a printer, and print to postscript files
16.50.4.extends JuliaSet1 and overrides the print() method to demonstrate the Java 1.2 printing API
16.50.5.Work with PrintRequestAttributeSet
16.50.6.PrinterJob and Printable
16.50.7.Print out a Swing component
16.50.8.Print Image
16.50.9.Printing to a File
16.50.10.Pagination during print
16.50.11.Printing Pages with Different Formats
16.50.12.The area of the printable area
16.50.13.The area of the actual page