The Java Tutorials have been written for JDK 8.Java教程是为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.有关Java SE 9及其后续版本中更新的语言特性的摘要,请参阅Java语言更改。
See JDK Release Notes for information about new features, enhancements, and removed or deprecated options for all JDK releases.有关所有JDK版本的新功能、增强功能以及已删除或不推荐的选项的信息,请参阅JDK发行说明。
The Java 2D API provides a useful set of standard shapes such as points, lines, rectangles, arcs, ellipses, and curves. Java2D API提供了一组有用的标准形状,如点、线、矩形、圆弧、椭圆和曲线。The most important package to define common geometric primitives is the 定义通用几何原语的最重要的包是java.awt.geom
package. java.awt.geom
包。Arbitrary shapes can be represented by combinations of straight geometric primitives.任意形状可以由直线几何图元的组合表示。
The Shape
interface represents a geometric shape, which has an outline and an interior. Shape
接口表示具有轮廓和内部的几何形状。This interface provides a common set of methods for describing and inspecting two-dimensional geometric objects and supports curved line segments and multiple sub-shapes. 此接口提供了一组用于描述和检查二维几何对象的通用方法,并支持曲线段和多个子形状。The Graphics
class supports only straight line segments. Graphics
类仅支持直线段。The Shape
interface can support curves segments.Shape
接口可以支持曲线段。
For more details about how to draw and fill shapes, see the Working with Geometry lesson.有关如何绘制和填充形状的详细信息,请参阅使用几何体课程。
The Point2D
class defines a point representing a location in (x, y) coordinate space. Point2D
类定义了一个点,表示(x, y)坐标空间中的位置。The term “point” in the Java 2D API is not the same as a pixel. 在Java 2D API中,这一术语“点”与像素并不相同。A point has no area, does not contain a color, and cannot be rendered.点没有区域,不包含颜色,并且无法渲染。
Points are used to create other shapes. 点用于创建其他形状。ThePoint2D
class also includes a method for calculating the distance between two points.Point2D
类还包括计算两点之间距离的方法。
The Line2D
class is an abstract class that represents a line. Line2D
类是表示线的抽象类。A line's coordinates can be retrieved as double. 直线的坐标可以双精度检索。The Line2D
class includes several methods for setting a line's endpoints.Line2D
类包括多个用于设置直线端点的方法。
You can also create a straight line segment by using the 还可以使用下面描述的GeneralPath
class described below.GeneralPath
类创建直线段。
The Rectangle2D
, RoundRectangle2D
, Arc2D
, and Ellipse2D
primitives are all derived from the RectangularShape
class. Rectangle2D
、RoundRectangle2D
、Arc2D
和Ellipse2D
原语都是从RectangleShape
类派生的。This class defines methods for 此类定义可由矩形边界框描述的Shape
objects that can be described by a rectangular bounding box. Shape
对象的方法。The geometry of a RectangularShape
object can be extrapolated from a rectangle that completely encloses the outline of the Shape
.RectangularShape
对象的几何图形可以从完全包围形状轮廓的矩形中推断出来。
The 使用QuadCurve2D
enables you to create quadratic parametric curve segments. QuadCurve2D
可以创建二次参数化曲线段。A quadratic curve is defined by two endpoints and one control point.二次曲线由两个端点和一个控制点定义。
The CubicCurve2D
class enables you to create cubic parametric curve segments. CubicCurve2D
类可用于创建立方参数化曲线段。A cubic curve is defined by two endpoints and two control points. 三次曲线由两个端点和两个控制点定义。The following are examples of quadratic and cubic curves. 以下是二次曲线和三次曲线的示例。See Stroking and Filling Graphics Primitives for implementations of cubic and quadratic curves.有关三次曲线和二次曲线的实现,请参阅笔划和填充图形原语。
This figure represents a quadratic curve.这个数字代表一条二次曲线。
This figure represents a cubic curve.这个数字代表一条三次曲线。
The GeneralPath
class enables you to construct an arbitrary shape by specifying a series of positions along the shape's boundary. GeneralPath
类允许您通过沿形状边界指定一系列位置来构造任意形状。These positions can be connected by line segments, quadratic curves, or cubic (Bézier) curves. 这些位置可以通过线段、二次曲线或三次(贝赛尔)曲线连接。The following shape can be created with three line segments and a cubic curve. 可以使用三条线段和一条三次曲线创建以下形状。See Stroking and Filling Graphics Primitivesfor more information about the implementation of this shape.有关此形状实现的详细信息,请参阅笔划和填充图形原语。
With the 使用Area
class, you can perform boolean operations, such as union, intersection, and subtraction, on any two Shape
objects. Area
类,可以对任意两个Shape
对象执行布尔运算,例如并集、交集和减法。This technique, often referred to as constructive area geometry, enables you to quickly create complex 此技术通常称为构造面积几何体,使您能够快速创建复杂Shape
objects without having to describe each line segment or curve.Shape
对象,而无需描述每条线段或曲线。