CSci 151: Foundations of computer science II
Home Syllabus Assignments Tests

Assignment 3: Windows

Due: 5:00pm, Friday, September 19. Value: 30 pts. Submit your solution (consisting of only) using the Sauron Submission System. [instructions]

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 that manages the list of windows available in a simple simulation of an overall user interface. We'll use a doubly linked list to track the list of windows

Screen shot of program

In the provided 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, there 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 three classes. All are complete except the Manager class; you should not modify the other classes.

Window Represents a single rectangular window.
Manager Manages the current list of windows.
Display Provides the overall application, including the main method.

Your assignment is to complete four crucial Manager methods for managing the list of windows. The only instance variables in Manager should be references to the top and bottom window on the simulated screen.

void add(Window toAdd)
Adds toAdd to this window list so that it appears at the top.
void remove(Window toRemove)
Removes toRemove from this window list.
Window find(int x, int y)
Returns the topmost window in this list containing the point (xy), or null if no windows contain the point.
void paintAll(Graphics g, Window current)
Paints all the windows in this list, starting with the bottommost. To paint an individual window, use its paint method, passing the g parameter to it and a boolean parameter indicating whether that window is current. You don't need to use the parameter g except to hand it to each individual window.

You want to use the following instance methods from Window.

boolean contains(int x, int y)
Returns true if (xy) lies within this window's boundary.
void paint(Graphics g, boolean selected)
Paints this window using g. If selected is true, the window is drawn with a thick border.
Window getWindowAbove()
Returns the window that this window believes is above it.
Window getWindowBelow()
Returns the window that this window believes is below it.
void setWindowAbove(Window value)
Changes the window that this window believes is above it.
void setWindowBelow(Window value)
Changes the window that this window believes is below it.