Addition using Point objects

My code increments a Point array using a predetermined NodeLength, I;ve searched online and can find no unclunky way of incrementing it beyond this:


double px = Point[1].getX();
int 1x = (int) px;

double py = Point[1].getY();
int 1y = (int) py;

1x += nodeLength;
1y += nodeLength;

Point[2].setLocation(1x,1y)


There’s got to be a better way than that right?

Point[2].setLocation( Point[1].getX() + nodeLength, Point[1].getY() + nodeLength );

Or you could add a method to your Point class.

Point {
   ...
   add(int x, int y) {
      this.setLocation( getX() + x, getY() + y );
   }

   set(Point p, int offset) {
      this.setLocation( p.getX() + offset, p.getY() + offset );
   }
}

Or something along those lines?

which was my first solution but point.getX() returns a double so you can’t add an int to it

SOLVED!

Point.x returns the x value as an int.

also, I’M AN IDIOT.

You seem to not be very familiar with the Java literal types and basic OO. I suggest you become more familiar with those before jumping to graphics.