DOC PREVIEW
Stanford CS 106A - Using Interactors

This preview shows page 1 out of 2 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 2 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 2 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Eric Roberts Handout #53CS 106A February 22, 2010Section Handout #7Using InteractorsThe purpose of this section is to give you some practice using the kind of interactors youneed for the FacePamphlet project in Assignment #5.The specific example is to build a framework for an interactive design tool that allows theuser to arrange boxes with labels on the window. The starting configuration for theprogram presents an empty graphics canvas and a control strip containing a JLabel, aJTextField, and three JButtons. The window as a whole then looks like this:NameAdd Remove ClearBoxDiagramThe most important operation in the program is to be able to add a new box to the screen,which you do by typing the name of the box in the JTextField and clicking the Addbutton. Doing so creates a new labeled box with that name in the center of the window.For example, if you entered the string Program in the JTextField and clicked Add, youwould see the following result:NameProgramAdd Remove ClearBoxDiagramProgramFor this simple version of the application, you may assume that the box always hasconstant dimensions, as specified by the following constant definitions:– 2 –private static final double BOX_WIDTH = 120;private static final double BOX_HEIGHT = 50;If you were to build a more sophisticated version, you could set the size by dragging arectangle on the screen.Once you have created a labeled box, your program should allow you to move the box asa unit by dragging it with the mouse. Because the outline and the label must movetogether, it makes sense to combine the GRect and GLabel into a GCompound and then usecode similiar to that in Figure 10-4 in the book to implement the dragging operation.The ability to create new boxes and drag them to new positions makes it possible to drawbox diagrams containing an arbitrary number of labeled boxes. For example, you couldadd three more boxes and drag them around to create the following diagram of theProgram class hierarchy:NameDialogProgramAdd Remove ClearBoxDiagramProgramConsoleProgram DialogProgram GraphicsProgramThe other two buttons in the control strip are Remove and Clear. The Remove buttonshould delete the box whose name appears in the JTextField; the Clear button shouldremove all of the boxes. While these operations are conceptually simple, they influencethe design in the following ways:• The fact that you may need to remove a box by name forces you to keep track of theobjects that appear in the window in some way that allows you to look up a labeledbox given the name that appears inside it. You therefore need some structure—andthere is an obvious choice in the Java Collection Framework—that keeps track of allthe boxes on the screen.• If the only objects in the window were the labeled boxes, you could implement theClear button by removing everything from the GCanvas. While that condition appliesfor this section assignment, you might want to extend this program so that there wereother objects on the screen that were part of the application itself that should stay onthe screen. In that case, you would want to implement Clear by going through the setof boxes on the screen and removing each


View Full Document

Stanford CS 106A - Using Interactors

Download Using Interactors
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Using Interactors and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Using Interactors 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?