Playing with Point Objects : Point « 2D Graphics « Java Tutorial






import java.awt.Point;

public class MainClass {
  public static void main(String[] args) {
    Point aPoint = new Point(); // Initialize to 0,0
    Point bPoint = new Point(50, 25);
    Point cPoint = new Point(bPoint);
    System.out.println("aPoint is located at: " + aPoint);
    aPoint.move(100, 50); // Change to position 100,50
    bPoint.x = 110;
    bPoint.y = 70;
    aPoint.translate(10, 20); // Move by 10 in x and 20 in y
    System.out.println("aPoint is now at: " + aPoint);
    if (aPoint.equals(bPoint))
      System.out.println("aPoint and bPoint are at the same location.");
  }
}
aPoint is located at: java.awt.Point[x=0,y=0]
aPoint is now at: java.awt.Point[x=110,y=70]
aPoint and bPoint are at the same location.








16.39.Point
16.39.1.java.awt.Point
16.39.2.Playing with Point Objects
16.39.3.Point class