Main Idea

Using a linked list, write the moveToTop method for the class named OverLappedRectangles that models a list of possibly overlapping rectangular two-dimensional window regions, like the windows for the programs open on your computer.

Details

You are to complete the class OverLappedRectangles.java

You are provided classes named WindowsTester.java, RectangleNode.java, Rectangle143.java, Rectangle.java, Point.java, and starter code for OverLappedRectangles.java

WindowsTester contains the method main and instantiates a JFrame to show what is happening with your code. Mouse clicks in the JFrame are sent to your class, to determine which rectangle should be moved to the top. To run a test on your program, all you do is click points in the JFrame. Each time you do so, the GUI is updated according to your code for moveToTop. The class WindowsTester displays the rectangles graphically. It is provided by, so you can guess how reliable it is. It is not at all robust, so occasionally no rectangles will appear at all. If that happens, close the JFrame and re-launch the program until they do appear. RectangleNode is a class that has a Rectangle143 as its data field and a pointer to the next RectangleNode.

OverLappedRectangles uses these nodes to form a linked list of Rectangle143 s.

Rectangle143 is a class derived from Rectangle and extends it by adding a Color field for the GUI display. Your OverLappedRectangles class will have a field consisting of an ArrayList of Rectangle143s. The class named Point is as we have used it before. See page 506 of textbook for description of Point class if you need further documentation.

Your rectangle list class, OverLappedRectangles, will keep a linked list of RectangleNodes to implement the model of possibly overlapping rectangular two-dimensional window regions.

Your rectangle list class will have a method, moveToTop, that takes a Point as a parameter, treats it as though the user clicked that Point on the screen, and moves the topmost rectangle touching that Point to the front of the list, leaving the order of the rest of the list unchanged. If the Point clicked is not on any of the rectangles, nothing is moved. To make your moveToTop method work correctly, you will need to determine which rectangle needs to be moved to the top by examining the coordinates of the Point passed to your method.

Important Points

  • The moveToTop method cannot use an array or ArrayList or any collection other than the linked list that is already in the class OverLappedRectangles. You must use linked list techniques only to solve this problem.
  • You do need to comment your method so that it is easily understood by anyone in this class.
  • You don’t need to java doc any of the methods provided to you, but you do need to javadoc any method you add to the class.
  • Be sure to write the header comment and the class javadoc comment to reflect your contribution.
Academic Honesty!
It is not our intention to break the school's academic policy. Projects posted are only used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly fill out the form. Please provide a valid email address and we'll get back to you in less than 24 hours. We will be sending an invoice through PayPal upon confirmation. We are a non profit organization however we need an amount to keep this organization running, and to be able to complete our research and development.