Java Reference
In-Depth Information
Section 13.6 Drawing Arcs
• An arc (p. 575) is drawn as a portion of an oval.
• Arcs sweep from a starting angle by the number of degrees specified by their arc angle (p. 575).
Graphics methods drawArc (p. 575) and fillArc (p. 575) are used for drawing arcs.
Section 13.7 Drawing Polygons and Polylines
• Class Polygon contains methods for creating polygons.
• Polygons are closed multisided shapes composed of straight-line segments.
• Polylines (p. 578) are sequences of connected points.
Graphics method drawPolyline (p. 580) displays a series of connected lines.
Graphics methods drawPolygon (p. 580) and fillPolygon (p. 581) are used to draw polygons.
Polygon method addPoint (p. 581) adds pairs of x - and y -coordinates to the Polygon .
Section 13.8 Java 2D API
• The Java 2D API (p. 581) provides advanced two-dimensional graphics capabilities.
• Class Graphics2D (p. 581)—a subclass of Graphics —is used for drawing with the Java 2D API.
• The Java 2D API's classes for drawing shapes include Line2D.Double , Rectangle2D.Double ,
RoundRectangle2D.Double , Arc2D.Double and Ellipse2D.Double (p. 581).
• Class GradientPaint (p. 584) helps draw a shape in gradually changing colors—called a gradient
(p. 584).
Graphics2D method fill (p. 584) draws a filled object of any type that implements interface
Shape ( p. 584).
• Class BasicStroke (p. 584) helps specify the drawing characteristics of lines.
Graphics2D method draw (p. 584) is used to draw a Shape object.
• Classes GradientPaint (p. 584) and TexturePaint (p. 585) help specify the characteristics for
filling shapes with colors or patterns.
• A general path (p. 586) is a shape constructed from straight lines and complex curves and is rep-
resented with an object of class GeneralPath (p. 586).
GeneralPath method moveTo (p. 587) specifies the first point in a general path.
GeneralPath method lineTo (p. 588) draws a line to the next point in the path. Each new call
to lineTo draws a line from the previous point to the current point.
GeneralPath method closePath (p. 588) draws a line from the last point to the point specified
in the last call to moveTo . This completes the general path.
Graphics2D method translate (p. 588) is used to move the drawing origin to a new location.
Graphics2D method rotate (p. 588) is used to rotate the next displayed shape.
Self-Review Exercises
13.1
Fill in the blanks in each of the following statements:
a)
In Java 2D, method
of class
sets the characteristics of a stroke used
to draw a shape.
b)
Class helps specify the fill for a shape such that the fill gradually changes from
one color to another.
c)
The
method of class Graphics draws a line between two points.
d)
RGB is short for
,
and
.
Search WWH ::




Custom Search