package elte.java2_utikalauz5.java2d; import java.awt.print.*; import java.awt.geom.*; import java.awt.*; /** peldaprogram egyszeru dokumentumok nyomtasara. @link.forrásfájl {@docRoot}/../data/java2d/src EgyszeruDokumentumNyomtato.java @link.letöltés {@docRoot}/../data/java2d EgyszeruDokumentumNyomtato.jar @since Java 2 Útikalauz programozóknak */ class EgyszeruDokumentumNyomtato implements Printable { Font betutipus = new Font ("Times New Roman", Font.BOLD, 36); public static void main (String[] args) { PrinterJob job = PrinterJob.getPrinterJob (); // egy Łj job-ot ad job.setPrintable (new EgyszeruDokumentumNyomtato ()); try { job.print (); } catch (Exception e) { System.out.println ("Hiba tortent a nyomtatas kozben!"); } } public int print (Graphics g, PageFormat pf, int pageIndex) throws PrinterException { if (pageIndex >= 3) return Printable.NO_SUCH_PAGE; Graphics2D g2 = (Graphics2D) g; g2.setFont (betutipus); g2.setColor (Color.black); g2.drawString ((pageIndex + 1) + ". oldal", 100, 100); BasicStroke bs = new BasicStroke (5.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER); g2.setStroke (bs); g2.setColor (Color.blue); Rectangle2D teglalap = new Rectangle2D.Float (210.0f, 150.0f, 150.0f, 200.0f); g2.draw (teglalap); return Printable.PAGE_EXISTS; } }