Windows

Supporting files:

Windows.java
Display.java
Manager.java
Window.java

Objectives:

Most graphical user interfaces are based on a stack of overlapping rectangles that we know as "windows." In this assignment, we'll create a class whose job is to manage the set of windows available in a simple simulation of an overall user interface.

In this user interface, the display is the gray area at the top of the application; the white text area below is a log of what has happened, to help with debugging.

When the application is working, you will be able to interact with windows in a variety of ways.

Distributed with this assignment are four classes. All are complete except the Manager class; you should not modify the other classes.

WindowRepresents a single rectangular window.
ManagerManages the current list of windows.
DisplayImplements the display interface.
WindowsProvides the overall application.

Your assignment is to complete four crucial methods for managing the list of windows.

void add(Window toAdd)
Adds toAdd to this window list so that it appears on top. Don't worry about what happens if the array is already full.

void remove(Window toRemove)
Removes toRemove from this window list.

Window find(int x, int y)
Returns the uppermost window in this list containing the point (x,y), or null if no windows contain the point. Note that this windowing system, like most, inverts the y-axis from what is conventionally used in mathematics: The y=0 line is at the display's top, and y increases as you move downward.

void paintAll(Graphics g)
Paints all the windows in this list, starting with the lowermost. To paint an individual window, use its paint method (passing the g parameter to it). You don't need to use the parameter g in way other than to hand it to each individual window.

The Manager class contains a windows instance variable, which is an array of Window objects that you should use for storing the current list of windows. You should use the windowCount instance variable to remember how many windows there currently are. Whether your array lists windows from the bottom up or from the top down is up to you.

Your implementation will need to use the following methods from the Window class.

int getX()
Returns the x-coordinate of this window's left edge.

int getY()
Returns the y-coordinate of this window's top edge.

int getWidth()
Returns the width of this window, in pixels.

int getHeight()
Returns the height of this window, in pixels.

void paint(Graphics g)
Paints this window using g.