The Java Tutorials have been written for JDK 8.Java教程是为JDK 8编写的。Examples and practices described in this page don't take advantage of improvements introduced in later releases and might use technology no longer available.本页中描述的示例和实践没有利用后续版本中引入的改进,并且可能使用不再可用的技术。See Java Language Changes for a summary of updated language features in Java SE 9 and subsequent releases.有关Java SE 9及其后续版本中更新的语言特性的摘要,请参阅Java语言更改。
See JDK Release Notes for information about new features, enhancements, and removed or deprecated options for all JDK releases.有关所有JDK版本的新功能、增强功能以及已删除或不推荐的选项的信息,请参阅JDK发行说明。
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 要在打印时使用Java 2D API功能,可以将Graphics
object to a Graphics2D
class, just like you do when you are rendering to the screen.Graphics
对象强制转换为Graphics2D
类,就像在屏幕上渲染一样。