Java Swing Tutorial - Java Point(Point p) Constructor








Syntax

Point(Point p) constructor from Point has the following syntax.

public Point(Point p)

Example

In the following code shows how to use Point.Point(Point p) constructor.

/* w w w. j  av a  2 s . co  m*/

import java.awt.Point;

public class Main {
  public static void main(String[] args) {
    Point aPoint = new Point();
    Point bPoint = new Point(50, 25);
    Point cPoint = new Point(bPoint);
    
    System.out.println("cPoint is located at: " + cPoint);
    
    System.out.println("aPoint is located at: " + aPoint);
    aPoint.move(100, 50);

    bPoint.x = 110;
    bPoint.y = 70;

    aPoint.translate(10, 20);
    System.out.println("aPoint is now at: " + aPoint);

    if (aPoint.equals(bPoint))
      System.out.println("aPoint and bPoint are at the same location.");
  }
}

The code above generates the following result.