Pointpublic class Point extends Point2D implements SerializableA point representing a location in {@code (x,y)} coordinate space,
specified in integer precision. |
Fields Summary |
---|
public int | xThe X coordinate of this Point .
If no X coordinate is set it will default to 0. | public int | yThe Y coordinate of this Point .
If no Y coordinate is set it will default to 0. | private static final long | serialVersionUID |
Constructors Summary |
---|
public Point()Constructs and initializes a point at the origin
(0, 0) of the coordinate space.
this(0, 0);
| public Point(Point p)Constructs and initializes a point with the same location as
the specified Point object.
this(p.x, p.y);
| public Point(int x, int y)Constructs and initializes a point at the specified
{@code (x,y)} location in the coordinate space.
this.x = x;
this.y = y;
|
Methods Summary |
---|
public boolean | equals(java.lang.Object obj)Determines whether or not two points are equal. Two instances of
Point2D are equal if the values of their
x and y member fields, representing
their position in the coordinate space, are the same.
if (obj instanceof Point) {
Point pt = (Point)obj;
return (x == pt.x) && (y == pt.y);
}
return super.equals(obj);
| public java.awt.Point | getLocation()Returns the location of this point.
This method is included for completeness, to parallel the
getLocation method of Component .
return new Point(x, y);
| public double | getX(){@inheritDoc}
return x;
| public double | getY(){@inheritDoc}
return y;
| public void | move(int x, int y)Moves this point to the specified location in the
{@code (x,y)} coordinate plane. This method
is identical with setLocation(int, int) .
this.x = x;
this.y = y;
| public void | setLocation(java.awt.Point p)Sets the location of the point to the specified location.
This method is included for completeness, to parallel the
setLocation method of Component .
setLocation(p.x, p.y);
| public void | setLocation(int x, int y)Changes the point to have the specified location.
This method is included for completeness, to parallel the
setLocation method of Component .
Its behavior is identical with move(int, int) .
move(x, y);
| public void | setLocation(double x, double y)Sets the location of this point to the specified double coordinates.
The double values will be rounded to integer values.
Any number smaller than Integer.MIN_VALUE
will be reset to MIN_VALUE , and any number
larger than Integer.MAX_VALUE will be
reset to MAX_VALUE .
this.x = (int) Math.floor(x+0.5);
this.y = (int) Math.floor(y+0.5);
| public java.lang.String | toString()Returns a string representation of this point and its location
in the {@code (x,y)} coordinate space. This method is
intended to be used only for debugging purposes, and the content
and format of the returned string may vary between implementations.
The returned string may be empty but may not be null .
return getClass().getName() + "[x=" + x + ",y=" + y + "]";
| public void | translate(int dx, int dy)Translates this point, at location {@code (x,y)},
by {@code dx} along the {@code x} axis and {@code dy}
along the {@code y} axis so that it now represents the point
{@code (x+dx,y+dy)}.
this.x += dx;
this.y += dy;
|
|