码迷,mamicode.com
首页 > 其他好文 > 详细

e681. 基本的打印程序

时间:2018-09-03 00:05:49      阅读:170      评论:0      收藏:0      [点我收藏+]

标签:java.awt   idt   lex   ima   cells   tran   efault   basic   amp   

Note that (0, 0) of the Graphics object is at the top-left of the actual page, outside the printable area. In this example, the Graphics object is translated so that (0, 0) becomes the top-left corner of the printable area.

    import java.awt.*;
    import java.awt.print.*;
    
    public class BasicPrint extends JComponent implements Printable {
        public int print(Graphics g, PageFormat pf, int pageIndex) {
            if (pageIndex > 0) {
                return Printable.NO_SUCH_PAGE;
            }
            Graphics2D g2d = (Graphics2D)g;
            g2d.translate(pf.getImageableX(), pf.getImageableY());
            drawGraphics(g2d, pf);
            return Printable.PAGE_EXISTS;
        }
    
        public static void main(String[] args) {
            PrinterJob pjob = PrinterJob.getPrinterJob();
            PageFormat pf = pjob.defaultPage();
            pjob.setPrintable(new BasicPrint(), pf);
            try {
                pjob.print();
            } catch (PrinterException e) {
            }
        }
    }

 

Related Examples

e681. 基本的打印程序

标签:java.awt   idt   lex   ima   cells   tran   efault   basic   amp   

原文地址:https://www.cnblogs.com/borter/p/9575587.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!