And that is confusing, isn't it. I think it means it creates a Point object at (x, y) and changes the size of the Rectangle object to include that Point. But I am not certain. The Point is not considered as included if it is on the lower or right edges. I don't think you are going to get a good explanation of that method anywhere; you might be able to paint that Rectangle object and add points to it. But why? It is old AWT code which has been superseded by Swing and Oracle seem to think that Swing has been superseded by JavaFX, so they are probably no longer updating either.public void add(int newx,
int newy)
Adds a point, specified by the integer arguments newx,newy to the bounds of this Rectangle.
If this Rectangle has any dimension less than zero, the rules for non-existant rectangles apply. In that case, the new bounds of this Rectangle will have a location equal to the specified coordinates and width and height equal to zero.
After adding a point, a call to contains with the added point as an argument does not necessarily return true. The contains method does not return true for points on the right or bottom edges of a Rectangle. Therefore, if the added point falls on the right or bottom edge of the enlarged Rectangle, contains returns false for that point. If the specified point must be contained within the new Rectangle, a 1x1 rectangle should be added instead:
r.add(newx, newy, 1, 1);
Parameters:
newx - the X coordinate of the new point
newy - the Y coordinate of the new point
Don't get me started about those stupid light bulbs. |