package com.lenovo.union.printreceipt.test; import java.awt.*; import java.awt.print.*; public class Test implements Printable { private static Font fnt = new Font("Helvetica", Font.PLAIN, 24); public static void main(String[] args) { // Get a PrinterJob PrinterJob job = PrinterJob.getPrinterJob(); // Specify the Printable is an instance of SimplePrint job.setPrintable(new Test()); // Put up the dialog box if (job.printDialog()) { // Print the job if the user didn't cancel printing try { job.print(); } catch (Exception e) { /* handle exception */} } System.exit(0); } public int print(Graphics g, PageFormat pf, int pageIndex) throws PrinterException { // pageIndex 0 to 4 corresponds to page numbers 1 to 5. if (pageIndex >= 1) { return Printable.NO_SUCH_PAGE; } g.setFont(fnt); g.setColor(Color.green); g.drawString("Page " + (pageIndex + 1), 100, 100); g.drawRect(200, 200, 400, 300); return Printable.PAGE_EXISTS; } }
- 1
- 粉丝: 0
- 资源: 8
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
- 1
- 2
- 3
- 4
- 5
- 6
前往页