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.
In prior lessons, you have learned the graphics concept, including basic information about the coordinate system and graphic object creation. Now, you will progress to more detailed lessons about the 2D graphics classes. This lesson shows you how to use the
Graphics2D
class to draw graphic primitives as well as arbitrary shapes, and how to display graphics with fancy outline and fill styles. These topics are discussed in the following sections.
This section explains how to create standard shapes such as points, lines, curves, arcs, rectangles, and ellipses.
This section explains how to draw shapes represented by combinations of straight geometric primitives by using the GeneralPath
class.
This section explains how to set the stroke and paint attributes to control the outline and fill styles applied to Shape
objects and text.