A point representing a location in (x, y) coordinate space, specified in integer precision.
@version
1.38, 12/19/03
@author
Sami Shaio
@since
JDK1.0
Constructs and initializes a point at the origin (0, 0) of the coordinate space.
@since
JDK1.1
Constructs and initializes a point with the same location as the specified Point object.
Parameters
pa point
@since
JDK1.1
Constructs and initializes a point at the specified (xy) location in the coordinate space.
Parameters
xthe x coordinate
ythe y coordinate
The x coordinate. If no x coordinate is set it will default to 0.
@serial
The y coordinate. If no y coordinate is set it will default to 0.
@serial
Creates a new object of the same class and with the same contents as this object.
Return
a clone of this instance.
Throws
OutOfMemoryErrorif there is not enough memory.
@since
1.2
Returns the distance from this Point2D to a specified point.
Parameters
PX, PYthe coordinates of the specified Point2D
Return
the distance between this Point2D and a specified point.
Returns the distance between two points.
Parameters
X1, Y1the coordinates of the first point
X2, Y2the coordinates of the second point
Return
the distance between the two sets of specified coordinates.
Returns the distance from this Point2D to a specified Point2D.
Parameters
ptthe specified Point2D
Return
the distance between this Point2D and the specified Point2D.
Returns the square of the distance from this Point2D to a specified point.
Parameters
PX, PYthe coordinates of the other point
Return
the square of the distance between this Point2D and the specified point.
Returns the square of the distance between two points.
Parameters
X1, Y1the coordinates of the first point
X2, Y2the coordinates of the second point
Return
the square of the distance between the two sets of specified coordinates.
Returns the square of the distance from this Point2D to a specified Point2D.
Parameters
ptthe specified Point2D
Return
the square of the distance between this Point2D to a specified Point2D.
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.
Parameters
objan 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.
Returns the runtime class of an object. That Class object is the object that is locked by static synchronized methods of the represented class.
Return
The java.lang.Class object that represents the runtime class of the object. The result is of type {@code Class} where X is the erasure of the static type of the expression on which getClass is called.
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
@since
JDK1.1
Returns the X coordinate of the point in double precision.
Return
the X coordinate of the point in double precision
Returns the Y coordinate of the point in double precision.
Return
the Y coordinate of the point in double precision
Returns the hashcode for this Point2D.
Return
a hash code for this Point2D.
Moves this point to the specified location in the (xy) coordinate plane. This method is identical with setLocation(int, int).
Parameters
xthe x coordinate of the new location
ythe y coordinate of the new location
Wakes up a single thread that is waiting on this object's monitor. If any threads are waiting on this object, one of them is chosen to be awakened. The choice is arbitrary and occurs at the discretion of the implementation. A thread waits on an object's monitor by calling one of the wait methods.

The awakened thread will not be able to proceed until the current thread relinquishes the lock on this object. The awakened thread will compete in the usual manner with any other threads that might be actively competing to synchronize on this object; for example, the awakened thread enjoys no reliable privilege or disadvantage in being the next thread to lock this object.

This method should only be called by a thread that is the owner of this object's monitor. A thread becomes the owner of the object's monitor in one of three ways:

  • By executing a synchronized instance method of that object.
  • By executing the body of a synchronized statement that synchronizes on the object.
  • For objects of type Class, by executing a synchronized static method of that class.

Only one thread at a time can own an object's monitor.

Throws
IllegalMonitorStateExceptionif the current thread is not the owner of this object's monitor.
Wakes up all threads that are waiting on this object's monitor. A thread waits on an object's monitor by calling one of the wait methods.

The awakened threads will not be able to proceed until the current thread relinquishes the lock on this object. The awakened threads will compete in the usual manner with any other threads that might be actively competing to synchronize on this object; for example, the awakened threads enjoy no reliable privilege or disadvantage in being the next thread to lock this object.

This method should only be called by a thread that is the owner of this object's monitor. See the notify method for a description of the ways in which a thread can become the owner of a monitor.

Throws
IllegalMonitorStateExceptionif the current thread is not the owner of this object's monitor.
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.
Parameters
xthe x coordinate of the new location
ythe y coordinate of the new location
See Also
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).

Parameters
xthe x coordinate of the new location
ythe y coordinate of the new location
@since
JDK1.1
Sets the location of the point to the specified location. This method is included for completeness, to parallel the setLocation method of Component.
Parameters
pa point, the new location for this point
@since
JDK1.1
Sets the location of this Point2D to the same coordinates as the specified Point2D object.
Parameters
pthe specified Point2D the which to set this Point2D
@since
1.2
Returns a string representation of this point and its location in the (xy) 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
Translates this point, at location (xy), by dx along the x axis and dy along the y axis so that it now represents the point (x + dx, y + dy).
Parameters
dxthe distance to move this point along the x axis
dythe distance to move this point along the y axis
Causes current thread to wait until another thread invokes the method or the method for this object. In other words, this method behaves exactly as if it simply performs the call wait(0).

The current thread must own this object's monitor. The thread releases ownership of this monitor and waits until another thread notifies threads waiting on this object's monitor to wake up either through a call to the notify method or the notifyAll method. The thread then waits until it can re-obtain ownership of the monitor and resumes execution.

As in the one argument version, interrupts and spurious wakeups are possible, and this method should always be used in a loop:

     synchronized (obj) {
         while (<condition does not hold>)
             obj.wait();
         ... // Perform action appropriate to condition
     }
 
This method should only be called by a thread that is the owner of this object's monitor. See the notify method for a description of the ways in which a thread can become the owner of a monitor.
Throws
IllegalMonitorStateExceptionif the current thread is not the owner of the object's monitor.
InterruptedExceptionif another thread interrupted the current thread before or while the current thread was waiting for a notification. The interrupted status of the current thread is cleared when this exception is thrown.
Causes current thread to wait until either another thread invokes the method or the method for this object, or a specified amount of time has elapsed.

The current thread must own this object's monitor.

This method causes the current thread (call it T) to place itself in the wait set for this object and then to relinquish any and all synchronization claims on this object. Thread T becomes disabled for thread scheduling purposes and lies dormant until one of four things happens:

  • Some other thread invokes the notify method for this object and thread T happens to be arbitrarily chosen as the thread to be awakened.
  • Some other thread invokes the notifyAll method for this object.
  • Some other thread interrupts thread T.
  • The specified amount of real time has elapsed, more or less. If timeout is zero, however, then real time is not taken into consideration and the thread simply waits until notified.
The thread T is then removed from the wait set for this object and re-enabled for thread scheduling. It then competes in the usual manner with other threads for the right to synchronize on the object; once it has gained control of the object, all its synchronization claims on the object are restored to the status quo ante - that is, to the situation as of the time that the wait method was invoked. Thread T then returns from the invocation of the wait method. Thus, on return from the wait method, the synchronization state of the object and of thread T is exactly as it was when the wait method was invoked.

A thread can also wake up without being notified, interrupted, or timing out, a so-called spurious wakeup. While this will rarely occur in practice, applications must guard against it by testing for the condition that should have caused the thread to be awakened, and continuing to wait if the condition is not satisfied. In other words, waits should always occur in loops, like this one:

     synchronized (obj) {
         while (<condition does not hold>)
             obj.wait(timeout);
         ... // Perform action appropriate to condition
     }
 
(For more information on this topic, see Section 3.2.3 in Doug Lea's "Concurrent Programming in Java (Second Edition)" (Addison-Wesley, 2000), or Item 50 in Joshua Bloch's "Effective Java Programming Language Guide" (Addison-Wesley, 2001).

If the current thread is interrupted by another thread while it is waiting, then an InterruptedException is thrown. This exception is not thrown until the lock status of this object has been restored as described above.

Note that the wait method, as it places the current thread into the wait set for this object, unlocks only this object; any other objects on which the current thread may be synchronized remain locked while the thread waits.

This method should only be called by a thread that is the owner of this object's monitor. See the notify method for a description of the ways in which a thread can become the owner of a monitor.

Parameters
timeoutthe maximum time to wait in milliseconds.
Throws
IllegalArgumentExceptionif the value of timeout is negative.
IllegalMonitorStateExceptionif the current thread is not the owner of the object's monitor.
InterruptedExceptionif another thread interrupted the current thread before or while the current thread was waiting for a notification. The interrupted status of the current thread is cleared when this exception is thrown.
Causes current thread to wait until another thread invokes the method or the method for this object, or some other thread interrupts the current thread, or a certain amount of real time has elapsed.

This method is similar to the wait method of one argument, but it allows finer control over the amount of time to wait for a notification before giving up. The amount of real time, measured in nanoseconds, is given by:

 1000000*timeout+nanos

In all other respects, this method does the same thing as the method of one argument. In particular, wait(0, 0) means the same thing as wait(0).

The current thread must own this object's monitor. The thread releases ownership of this monitor and waits until either of the following two conditions has occurred:

  • Another thread notifies threads waiting on this object's monitor to wake up either through a call to the notify method or the notifyAll method.
  • The timeout period, specified by timeout milliseconds plus nanos nanoseconds arguments, has elapsed.

The thread then waits until it can re-obtain ownership of the monitor and resumes execution.

As in the one argument version, interrupts and spurious wakeups are possible, and this method should always be used in a loop:

     synchronized (obj) {
         while (<condition does not hold>)
             obj.wait(timeout, nanos);
         ... // Perform action appropriate to condition
     }
 
This method should only be called by a thread that is the owner of this object's monitor. See the notify method for a description of the ways in which a thread can become the owner of a monitor.
Parameters
timeoutthe maximum time to wait in milliseconds.
nanosadditional time, in nanoseconds range 0-999999.
Throws
IllegalArgumentExceptionif the value of timeout is negative or the value of nanos is not in the range 0-999999.
IllegalMonitorStateExceptionif the current thread is not the owner of this object's monitor.
InterruptedExceptionif another thread interrupted the current thread before or while the current thread was waiting for a notification. The interrupted status of the current thread is cleared when this exception is thrown.