Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Window Manager java program. What to Do Open Eclipse and create a project named Assignment05 . You'll need StdDraw for this project, so make sure

Window Manager java program.

What to Do

Open Eclipse and create a project named Assignment05. You'll need StdDraw for this project, so make sure you can import it. You'll need to create implement three classes:

Window

WindowDisplay

WindowDriver

The details of each class are given below:

Window

The Window class represents 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 privates variable of type double for the half-width and half-height of the window (remember, StdDraw works with half-dimensions).

A private variable of type Color for the color of the window.

Methods:

A constructor that takes the x and y-coordinates, width, height, and color of the window. It should set the instance variable using these arguments.

A draw() method that draws the window using StdDraw.

A contains(double x, double y) method that takes two arguments of type double: an x and y-coordinate representing a point. This method should return true if the point is inside the window, and false if it is not.

WindowDisplay

The WindowDisplay class stores a list of windows, and updates 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 the StdDraw 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 create an empty list. It should also initialize StdDraw with the given width and height (use these for both the scale and size of the canvas).

An addWindow(Window w) method that has one parameter of type Window. This method should add this Window to its list of windows.

A run() method that contains our (infinite) animation loop. This loop is responsible for:

Displaying the canvas.

Capturing mouse clicks. (Hint: StdDraw has StdDraw.isMousePressed(), StdDraw.mouseX(), and StdDraw.mouseY())

Rearranging the windows to move windows that were clicked on to the top.

Create any additional private methods to divide up the work and make your code easier to read. For example, you might have a method for finding which Window was clicked, or a method to rearrange the list of windows to move a given Window to the top.

WindowDriver

The WindowDriver class should contain a main method that runs the simulation. Here is the code I used to create the demonstration video (https://videomanager.du.edu/private/5349999f1abd6):

public static void main(String[] args) { WindowDisplay w = new WindowDisplay(200, 200); Window w1 = new Window(50, 50, 30, 40, StdDraw.BLUE); w.addWindow(w1); Window w2 = new Window(100, 130, 40, 40, StdDraw.RED); w.addWindow(w2); Window w3 = new Window(80, 80, 30, 40, StdDraw.GREEN); w.addWindow(w3); Window w4 = new Window(120, 60, 50, 40, 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.

Extra Credit

For (up to) 10 extra points, make the windows "draggable," so you can move them around with the mouse.

What to Submit

When you are finished, submit a zip of your project to Canvas. This should at least include:

Window.java

WindowDisplay.java

WindowDriver.java

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Relational Database And Transact SQL

Authors: Lucy Scott

1st Edition

1974679985, 978-1974679980

Students also viewed these Databases questions