Documentation

The Java™ Tutorials
Hide TOC
Printing打印
Trail: 2D Graphics
Lesson: Overview of the Java 2D API Concepts

Printing打印

All of the Swing and Java 2D graphics, including composited graphics and images, can be rendered to a printer by using the Java 2D Printing API. 所有Swing和Java 2D图形(包括合成图形和图像)都可以使用Java 2D打印API渲染到打印机。This API also provides document composition features that enable you to perform such operations as changing the order in which pages are printed.此API还提供文档合成功能,使您能够执行诸如更改页面打印顺序等操作。

Rendering to a printer is like rendering to a screen. 渲染到打印机就像渲染到屏幕一样。The printing system controls when pages are rendered, just like the drawing system controls when a component is painted on the screen.打印系统控制渲染页面的时间,就像绘图系统控制在屏幕上绘制组件的时间一样。

The Java 2D Printing API is based on a callback model in which the printing system, not the application, controls when pages are printed. Java2D打印API基于回调模型,在该模型中,打印系统(而不是应用程序)控制打印页面的时间。The application provides the printing system with information about the document to be printed, and the printing system determines when each page needs to be imaged.该应用程序向打印系统提供有关要打印的文档的信息,打印系统确定每页何时需要成像。

The following two features are important to support printing:以下两个功能对于支持打印非常重要:

When pages need to be imaged, the printing system calls the application's print method with an appropriate Graphics context. 当页面需要成像时,打印系统使用适当的Graphics上下文调用应用程序的print方法。To use Java 2D API features when you print, you cast the Graphics object to a Graphics2D class, just like you do when you are rendering to the screen.要在打印时使用Java 2D API功能,可以将Graphics对象强制转换为Graphics2D类,就像在屏幕上渲染一样。


Previous page: Images
Next page: Getting Started with Graphics