How It Works
This time you create all the shapes first and then draw them. The two arcs are segments of ellipses of the
same height and width. The lower arc segment is shifted up with respect to the first arc segment so that
they intersect, and the distance between the top of the rectangle for the first arc and the bottom of the
rectangle for the second arc is diameter , which is the diameter of the first circle you create.
Both circles are created centered between the two arcs and are concentric. Finally, you draw all the shapes
— the arcs in black and the circles in blue.
Next time you change the code in Sketcher, you build the application as it should be, so you can now
remove the temporary code from the paint() method and, if you haven't done so already, also remove
the code that sets the background color in the ColorAction inner class to the SketcherFrame class.
There are two classes that define arbitrary curves, one defining a quadratic or second-order curve, and the
other defining a cubic curve. These arbitrary curves are parametric curves defined by a sequence of curve
segments. A quadratic curve segment is defined by an equation that includes squares of the independent
variable, x . A cubic curve is defined by an equation that includes cubes of the independent variable, x . The
cubic curve just happens to be a Bézier curve (so called because it was developed by a Frenchman, Monsieur
Pierre Bézier, and first applied in the context of defining contours for programming numerically controlled
machine tools for manufacturing car body forms).
The classes defining these curves are:
• QuadCurve2D : This is the abstract base class for the QuadCurve2D.Double and
QuadCurve2D.Float classes that define a quadratic curve segment. The curve is defined by its
end points plus a control point that defines the tangent at each end. The tangents are the lines from
the end points to the control point.
• CubicCurve2D : This is the abstract base class for the CubicCurve2D.Double and Cu-
bicCurve2D.Float classes that define a cubic curve segment. The curve is defined by its end
points plus two control points that define the tangent at each end. The tangents are the lines from
the end points to the corresponding control point.