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发行说明。
Constructive area geometry (CAG) is the process of creating new geometric shapes by performing boolean operations on existing ones.构造区域几何(CAG)是通过对现有几何图形执行布尔运算来创建新几何图形的过程。In the Java 2D API the 在Java2D API中,Area
class implements the Shape
interface and supports the following boolean operations.Area
类实现了Shape
接口并支持以下布尔操作。
![]() |
![]() |
||
![]() |
![]() |
XOR ) |
In this example 在本例中,区域对象从几个椭圆构造梨形。Area
objects construct a pear shape from several ellipses.
Pear.java
contains the complete code for this applet.包含此小程序的完整代码。
The leaves are each created by performing an intersection on two overlapping circles.每个叶子都是通过在两个重叠的圆上执行相交来创建的。
leaf = new Ellipse2D.Double(); ... leaf1 = new Area(leaf); leaf2 = new Area(leaf); ... leaf.setFrame(ew-16, eh-29, 15.0, 15.0); leaf1 = new Area(leaf); leaf.setFrame(ew-14, eh-47, 30.0, 30.0); leaf2 = new Area(leaf); leaf1.intersect(leaf2); g2.fill(leaf1); ... leaf.setFrame(ew+1, eh-29, 15.0, 15.0); leaf1 = new Area(leaf); leaf2.intersect(leaf1); g2.fill(leaf2);
Overlapping circles are also used to construct the stem through a subtraction operation.重叠圆也用于通过减法运算构造杆。
stem = new Ellipse2D.Double(); ... stem.setFrame(ew, eh-42, 40.0, 40.0); st1 = new Area(stem); stem.setFrame(ew+3, eh-47, 50.0, 50.0); st2 = new Area(stem); st1.subtract(st2); g2.fill(st1);
The body of the pear is constructed by performing a union operation on a circle and an oval.梨体是通过在一个圆和一个椭圆形上执行并集操作来构建的。
circle = new Ellipse2D.Double(); oval = new Ellipse2D.Double(); circ = new Area(circle); ov = new Area(oval); ... circle.setFrame(ew-25, eh, 50.0, 50.0); oval.setFrame(ew-19, eh-20, 40.0, 70.0); circ = new Area(circle); ov = new Area(oval); circ.add(ov); g2.fill(circ);