Start of Tutorial > Start of Trail > Start of Lesson |
Search
Feedback Form |
The classes in thejava.awt.geom
package define common graphics primitives, such as points, lines, curves, arcs, rectangles, and ellipses.
Classes in the
java.awt.geom
PackageArc2D
Ellipse2D
QuadCurve2D
Area
GeneralPath
Rectangle2D
CubicCurve2D
Line2D
RectangularShape
Dimension2D
Point2D
RoundRectangle2D
Except for
Point2D
andDimension2D
, each of the geometry classes (geometries) implements theShape
interface, which provides a common set of methods for describing and inspecting two-dimensional geometric objects.With these classes you can create virtually any geometric shape and render it through
Graphics2D
by calling thedraw
method or thefill
method. For example, the geometric shapes in the followingShapesDemo2D
applet are defined by using basic Java 2D geometries.If you're curious, the code for this program, is in
ShapesDemo2D.java
. How to draw and fill shapes is described in the next lesson, Displaying Graphics with Graphics2D.
This figure has been reduced to fit on the page.
Click the image to view it at its natural size.Rectangular Shapes
TheRectangle2D
,RoundRectangle2D
,Arc2D
, andEllipse2D
primitives are all derived fromRectangularShape
, which defines methods forShape
objects that can be described by a rectangular bounding box. The geometry of aRectangularShape
can be extrapolated from a rectangle that completely encloses the outline of theShape
.QuadCurve2D and CubicCurve2D
TheQuadCurve2D
class allows you to create quadratic parametric curve segments. A quadratic curve is defined by two endpoints and one control point.The
CubicCurve2D
class allows you to create cubic parametric curve segments. A cubic curve is defined by two endpoints and two control points. The following figures demonstrate examples of quadratic and cubic curves. See Stroking and Filling Graphics Primitives to see implementations of cubic and quadratic curves.GeneralPath
TheGeneralPath
class enables you to construct an arbitrary shape by specifying a series of positions along the shape's boundary. These positions can be connected by line segments, quadratic curves, or cubic (Bézier) curves. The shape pictured below can be created with three line segments and a cubic curve. See Stroking and Filling Graphics Primitives to see the implementation of this shape.Areas
With theArea
class you can perform boolean operations, such as union, intersection, and subtraction, on any twoShape
objects. This technique, often referred to as constructive area geometry, enables you to quickly create complexShape
objects without having to describe each line segment or curve.
Start of Tutorial > Start of Trail > Start of Lesson Search
Feedback FormCopyright 1995-2005 Sun Microsystems, Inc. All rights reserved.