Using java language
Assume you have a graphical user interface with a bunch ofRectangles that you added
randomly all over the screen, and saved in anArrayList<Rectangle> called
rectangles. The built-in Rectangle shape class is notimplemented to be Comparable,
but you want to be able to sort the rectangles in order of howthey appear in the interface from
left to right. If two Rectangles align on the left, theRectangle up higher in the interface should
come first. Note: the built-in Rectangle class has methodsgetX(), getY(),
getWidth(), and getHeight(), all of which return a double. Writeyour own comparator
so that you can use the following line to sort yourRectangles:
Collections.sort(rectangles, new MyRectangleComparator());
—————————————————————-
import java.util.Comparator;
public class MyRectangleComparator
Expert Answer
Answer to Using java language Assume you have a graphical user interface with a bunch of Rectangles that you added randomly all ov…