Java 2D Graphics line segments and multiple sub-shapes,
Java 2D Graphics line segments and multiple sub-shapes, as you’ll see later. 3.2.1 java.awt.Shape The java.awt.Shape interface is one of the common currencies of the 2D API. It contains four groups of methods: getBounds(), contains(), intersects(), and getPathIterator(). The getBounds() methods return rectangles that completely enclose a Shape: public abstract Rectangle getBounds() This method returns a java.awt.Rectangle that completely encloses the Shape. Rectangle stores its coordinates as integers. public abstract Rectangle2D getBounds2D() This method returns a java.awt.geom.Rectangle2D that completely encloses the Shape. Rectangle2D returns its coordinates as doubles. This method provides a higher precision bounding box than getBounds(); you should use it unless you have a specific reason to work with integer coordinates. The initial release of Java 2 (formerly JDK 1.2) contains a bug in Arc2D’s implementation of . The returned rectangle is the right size but in the wrong place. This bug is fixed in JDK 1.2.1. Figure 3.2 shows the bounds rectangles of a few shapes. Figure 3.2. Bounds rectangles A Shape has an interior and an exterior. You can see if a point or rectangle is inside the Shape using the contains() methods: public abstract boolean contains(double x, double y) public abstract boolean contains(Point2D p) These methods return true if the Shape contains the given point. This can actually be pretty complicated, as you can see from the right side of Figure 3.2. I’ll explain how the interior of a shape is determined later in this chapter. public abstract boolean contains(double x, double y, double w, double h) public abstract boolean contains(Rectangle2D r) These methods return true if the given rectangle is completely in the interior of the Shape. page 28
Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Tomcat Web Hosting services