Java Reference
In-Depth Information
To use Area , first pass a Shape object to its Area(Shape s) constructor and
theninvokeoneoftheaforementionedmethodsonthis Area objecttoperformtheop-
eration.Because Area alsoimplements Shape ,youcanpassthe Area objectwiththe
Boolean result to Graphics2D 's draw() and fill() methods.
The following example demonstrates the union operation on a pair of ellipses:
Ellipse2D ell1 = new Ellipse2D.Double(10.0, 10.0, 40.0,
Ellipse2D ell2 = new Ellipse2D.Double(30.0, 10.0, 40.0,
Area area1 = new Area(ell1);
Area area2 = new Area(ell2);
Aftercreatingtwoellipseshapes,theexamplecreatestwo Area objects,whereeach
objectcontainsoneellipse.Ittheninvokes add() onthefirst Area objecttocreatea
unionofpixelsinthearearangingfromupper-leftcorner( 10.0 , 10.0 )tolower-right
corner ( 70.0 , 50.0 ). The result is stored in the first Area object.
tion's output appears in Figure 7-27 .
Figure 7-27. Press the mouse pointer over the round rectangle to begin dragging this
Buffered Images
AWT's Image classassociateswitharectangulararrayofcoloredpixels.Althoughyou
can draw these pixels (via drawImage() ), you need to work with AWT's somewhat
tedious producer/consumer model (which I don't discuss for brevity) to access them.
In contrast, Java 2D's java.awt.image.BufferedImage class, which extends
Image , makes these pixels available to applications and is easier to use.
Search WWH ::

Custom Search