The Java Tutorials have been written for 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.
See JDK Release Notes for information about new features, enhancements, and removed or deprecated options for all JDK releases.
This lesson shows you how to use Graphics2D
to display graphics with fancy outline and fill styles, transform graphics when they are rendered, constrain rendering to a particular area, and generally control the way graphics look when they are rendered. You'll also learn how to create complex Shape
objects by combining simple ones and how to detect when the user clicks on a displayed graphics primitive. These topics are discussed in the following sections:
This section shows you how to modify the default transformation so that objects are translated, rotated, scaled, or sheared when they are rendered.
You can use any shape as a clipping path—the area within which rendering takes place.
This section illustrates the various compositing styles supported by AlphaComposite
and shows you how to set the compositing style in the Graphics2D
rendering context.
This section describes the rendering hints that Graphics2D
supports and shows you how to specify your preference in the trade-off between rendering quality and speed.
This section shows you how to perform boolean operations on Shape
objects using the Area
class.
This section shows you how to perform hit detection on graphics primitives.