Java 2D Graphics The original java.awt.Point, which dates
Java 2D Graphics The original java.awt.Point, which dates back to JDK 1.0, stores the coordinates as integers. Java 2D provides Point2D.Float and Point2D.Double for higher precision. Find Your Inner Child What’s an inner child class? An inner class , introduced to the Java language in JDK 1.1, is a class that is defined inside another class. For example, a class called Painter might have an inner class called Raphael. The full name of that inner class is Painter.Raphael. A child class is a class that extends another class. In the AWT, for example, classes like Button and Canvas extend the Component class. An inner child class combines both of these techniques: it is a class that is defined inside its own superclass. Inner child classes are a recurring theme in the java.awt.geom package. The Point2D class, for example, has two inner child classes, called Point2D.Double and Point2D.Float. For more information on inner classes, see Java in a Nutshell, by David Flanagan (O’Reilly), or Exploring Java, by Pat Niemeyer and Josh Peck (O’Reilly). You can either set a point’s location or find out where it is: public abstract void setLocation(double x, double y) This method sets the position of the point. Although it accepts double values, be aware that the underlying implementation may not store the coordinates as double values. public abstract void setLocation(Point2D p) This method sets the position of the point using the coordinates of another Point2D. public abstract double getX() This method returns the x (horizontal) coordinate of the point as a double. public abstract double getY() This method returns the y (vertical) coordinate of the point as a double. Point2D also includes a handy method for calculating the distance between two points: public double distance(double PX, double PY) Use this method to calculate the distance between this Point2D and the point specified by PX and PY. public double distance(Point2D pt) This method calculates the distance between this Point2D and pt. page 26
Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Java Web Hosting services