|
|
Overview of the Java 2D API |
The classes in thejava.awt.geompackage define common graphics primitives, such as points, lines, curves, arcs, rectangles, and ellipses.
Classes in the
java.awt.geomPackageArc2DEllipse2DQuadCurve2DAreaGeneralPathRectangle2DCubicCurve2DLine2DRectangularShapeDimension2DPoint2DRoundRectangle2DExcept for
Point2DandDimension2D, each of the geometry classes (geometries) implements theShapeinterface, 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
Graphics2Dby calling thedrawmethod or thefillmethod. For example, the geometric shapes in the followingShapesDemo2Dapplet 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.Rectangular Shapes
TheRectangle2D,RoundRectangle2D,Arc2D, andEllipse2Dprimitives are all derived fromRectangularShape, which defines methods forShapeobjects that can be described by a rectangular bounding box. The geometry of aRectangularShapecan be extrapolated from a rectangle that completely encloses the outline of theShape.GeneralPath
TheGeneralPathclass 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.Areas
With theAreaclass you can perform boolean operations, such as union, intersection, and subtraction, on any twoShapeobjects. This technique, often referred to as constructive area geometry, enables you to quickly create complexShapeobjects without having to describe each line segment or curve.
|
|
Overview of the Java 2D API |