Question: Write a program that models a list of possibly overlapping rectangular two-dimensional windows, like the windows for the programs open on your computer. Use an
Write a program that models a list of possibly overlapping rectangular two-dimensional windows, like the windows for the programs open on your computer. Use an ArrayList to store the windows. The order of the windows in the list implies the order in which they would display on the screen (sometimes called the z- order), from 0 on the bottom to size() 1 on the top. When a user clicks on a window, it will move to the top. When rectangles overlap, only the top rectangle is considered to be clicked.
Your project should have three classes: Window, WindowDisplay, and WindowDriver. You will also need to include the StdDraw class in your project.
The Window class will represent a single window. It should contain the following:
Instance variables:
Two private variables of type double for the x and y coordinates of the center of the window.
Two private variable of type double for the width and height of the window.
A private variable of type Color for the color of the window. (You will need to import java.awt.Color.)
Methods:
A constructor that takes the x and y-coordinates, width, height, and color of the window. This constructor should use its parameter to set the instance variables.
A method that displays (draws) a single window.
A method that has two parameters, an xcoordinate and a y-coordinate. This method should return true if the x-coordinate and y-coordinate are located within the window and false if they are not.
The WindowDisplay class will keep a list of all windows and update the list when the mouse is clicked on a specific window.
Instance variables:
A private ArrayList of windows
Two private int variables that store the width and height of StdDraws canvas.
Methods:
A constructor that takes two arguments, the width and height of the StdDraw canvas. The constructor should initialize the width and height instance variables and should create an empty list. It should also set the StdDraw canvas size and the x and y scale.
A public addWindow method that has one parameter of type Window. The addWindow method should add this window to the list of windows.
A public run method that is responsible for displaying the canvas and capturing mouse clicks. Hint: StdDraw has a mousePressed method that you will find useful. See the StdDraw documentation for more information.
In addition, you should create private methods that divide up the work and make your code easier to read. These might include a method that that is responsible for displaying all windows on the canvas, and a method that determines if the mouse was pressed in a specific window and then reorders the list accordingly. You should use the class StdDraw to create your graphical representation. The WindowDriver class should contain the main method that starts the simulation. Here is the code I used to create the demonstration video:
public static void main(String[] args) { WindowDisplay w = new WindowDisplay(200, 200); Window w1 = new Window(50, 50, 60, 80, StdDraw.BLUE); w.addWindow(w1); Window w2 = new Window(100, 130, 80, 80, StdDraw.RED); w.addWindow(w2); Window w3 = new Window(80, 80, 60, 80, StdDraw.GREEN); w.addWindow(w3); Window w4 = new Window(120, 60, 100, 80, StdDraw.BLACK); w.addWindow(w4); w.run(); } This code creates a 200 x 200 canvas and then adds four windows to the display. It then starts the simulation. Here is a link to a video that shows the simulation: https://videomanager.du.edu/private/5349999f1abd6
The white circles are used to indicate mouse clicks. You do not need to include the white circles in your code.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
