Java 2D Graphics The original java.awt.Point, which dates
Java 2D Graphics The inner child class Point2D.Double has two constructors: public Point2D.Double() This constructor creates a Point2D.Double at the coordinates 0, 0. public Point2D.Double(double x, double y) This constructor creates a Point2D.Double at the given coordinates. Point2D.Float has a similar pair of constructors, based around floats instead of doubles: public Point2D.Float() public Point2D.Float(float x, float y) Furthermore, Point2D.Float provides an additional setLocation() method that accepts floats instead of doubles: public void setLocation(float x, float y) This method sets the location of the point using the given coordinates. Why use floats instead of doubles? If you have special concerns about the speed of your application or interfacing with an existing body of code, you might want to use Point2D.Float. Otherwise, I suggest using Point2D.Double, since it provides the highest level of precision. 3.2 Shapes and Paths As you saw in Chapter 2, the Graphics2D class is the rendering engine for the Java 2D API. Two of its basic operations are filling shapes and drawing their outlines. But Graphics2D doesn’t know much about geometry, as the song says. In fact, Graphics2D only knows how to draw one thing: a java.awt.Shape. The Shape interface represents a geometric shape, something that has an outline and an interior. With Graphics2D, you can draw the border of the shape using draw(), and you can fill the inside of a shape using fill(). The java.awt.geom package is a toolbox of useful classes that implement the Shape interface. There are classes that represent ellipses, arcs, rectangles, and lines. First, I’ll talk about the Shapeinterface, and then briefly discuss the java.awt.geom package. If You’re an Old Dog You probably remember that the Graphics class had methods for drawing and filling simple shapes: drawRect(), drawOval(), drawArc(), fillRect(), fillOval(), fillArc(), etc. Because Graphics2D is a subclass of Graphics, you can still call these methods to render shapes. In some cases, it’s easier to call one of these methods, because you can render a shape in a single step. On the other hand, these methods use only integer coordinates, and they don’t allow you to reuse shapes. Furthermore, the most complex shape that Graphics supports is a polygon defined with straight line segments. The Shape interface also supports curved page 27
Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Java Web Hosting services