Printing

You can print a Graphics object—but not just any Graphics object; you can only print a PrintGraphics object. You can either manually draw into the graphics or have a component draw into it; either way, after you are done painting into the graphics, you can turn around and print it. If a component prints into the graphics object and the component is a container, you can choose to print all of the components contained within the container's containment hierarchy.

Obtaining a Reference to a PrintGraphics

Whether you want to paint a (hierarchy of) component(s) or you just want to paint into a graphics object and then print it, you must first obtain a reference to a special extension of the Graphics class—a PrintGraphics. This is a four-step ...

Get Graphic Java™ 1.2, Volume I: AWT, Third Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.