'How to combine rectangles?

I am working with the Java Swing library. I have two rectangles of the same width and height and the same coordinates. I want to combine them into one so I can get a cross. How can I achieve it?



Solution 1:[1]

Construct a new Area(Shape) of both rectangles, then area1.add(area2) (add one to the other).

See also the 2D Graphics trail of the tutorial.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Andrew Thompson