FileDocCategorySizeDatePackage
Point.javaAPI DocJava SE 6 API6584Tue Jun 10 00:25:18 BST 2008java.awt

Point

public class Point extends Point2D implements Serializable
A point representing a location in {@code (x,y)} coordinate space, specified in integer precision.
version
1.40, 02/24/06
author
Sami Shaio
since
1.0

Fields Summary
public int
x
The X coordinate of this Point. If no X coordinate is set it will default to 0.
public int
y
The 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.

since
1.1


                                
      
	this(0, 0);
    
public Point(Point p)
Constructs and initializes a point with the same location as the specified Point object.

param
p a point
since
1.1

	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.

param
x the X coordinate of the newly constructed Point
param
y the Y coordinate of the newly constructed Point
since
1.0

	this.x = x;
	this.y = y;
    
Methods Summary
public booleanequals(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.

param
obj an object to be compared with this Point2D
return
true if the object to be compared is an instance of Point2D and has the same values; false otherwise.

	if (obj instanceof Point) {
	    Point pt = (Point)obj;
	    return (x == pt.x) && (y == pt.y);
	}
	return super.equals(obj);
    
public java.awt.PointgetLocation()
Returns the location of this point. This method is included for completeness, to parallel the getLocation method of Component.

return
a copy of this point, at the same location
see
java.awt.Component#getLocation
see
java.awt.Point#setLocation(java.awt.Point)
see
java.awt.Point#setLocation(int, int)
since
1.1

	return new Point(x, y);
    
public doublegetX()
{@inheritDoc}

since
1.2

	return x;
    
public doublegetY()
{@inheritDoc}

since
1.2

	return y;
    
public voidmove(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).

param
x the X coordinate of the new location
param
y the Y coordinate of the new location
see
java.awt.Component#setLocation(int, int)

	this.x = x;
	this.y = y;
    
public voidsetLocation(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.

param
p a point, the new location for this point
see
java.awt.Component#setLocation(java.awt.Point)
see
java.awt.Point#getLocation
since
1.1

	setLocation(p.x, p.y);
    
public voidsetLocation(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).

param
x the X coordinate of the new location
param
y the Y coordinate of the new location
see
java.awt.Component#setLocation(int, int)
see
java.awt.Point#getLocation
see
java.awt.Point#move(int, int)
since
1.1

	move(x, y);
    
public voidsetLocation(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.

param
x the X coordinate of the new location
param
y the Y coordinate of the new location
see
#getLocation

	this.x = (int) Math.floor(x+0.5);
	this.y = (int) Math.floor(y+0.5);
    
public java.lang.StringtoString()
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
a string representation of this point

	return getClass().getName() + "[x=" + x + ",y=" + y + "]";
    
public voidtranslate(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)}.

param
dx the distance to move this point along the X axis
param
dy the distance to move this point along the Y axis

	this.x += dx;
	this.y += dy;