38-section-7

38-section-7 - Mehran Sahami CS 106A Handout #38 November...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Mehran Sahami Handout #38 CS 106A November 9, 2009 Section Handout #7: Using Interactors and the Debugger Based on a handout by Eric Roberts 1. Using Interactors The purpose of this problem is to give you some practice using the kind of interactors you need for the NameSurfer project in Assignment #6. The specific example is to build a framework for an interactive design tool that allows the user to arrange boxes with labels on the window. The starting configuration for the program presents an empty graphics canvas and a control bar containing a JLabel , a JTextField , and three JButton s. The window as a whole then looks like this: The 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 Add button. 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 , you would see the following result:
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2 For this simple version of the application, you may assume that the box always has constant dimensions, as specified by the following constant definitions: private static final double BOX_WIDTH = 120; private static final double BOX_HEIGHT = 50; Once you have created a labeled box, your program should allow you to move the box as a unit by dragging it with the mouse. Because the outline and the label must move together, it makes sense to combine the GRect and GLabel into a GCompound and then use code similar 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 draw box diagrams containing an arbitrary number of labeled boxes. For example, you could add three more boxes with names GraphicsProgram , ConsoleProgram , and DialogProgram respectively, and drag them around to create this diagram of the
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 5

38-section-7 - Mehran Sahami CS 106A Handout #38 November...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online