📄 e681. the quintessential printing program.txt
字号:
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) {
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -