34a-section-6-solutions

34a-section-6-solutions - Handout#34A CS 106A Aug 4 2009...

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Handout #34A CS 106A Aug 4, 2009 Solution to Section #6 1. BoxDiagram import java.awt.event.*; import java.util.*; import javax.swing.*; import acm.program.*; /** * This program allows the user to create a set of boxes with labels * and then drag them around in the window. */ public class BoxDiagram extends GraphicsProgram { /* Private constants */ private static final int MAX_NAME = 25; /* Private instance variables */ private HashMap<String,LabeledBox> boxes; private JTextField nameField; private JButton addButton; private JButton removeButton; private JButton clearButton; private LabeledBox currentlyMovingBox; /* Initializes the program */ public void run() { boxes = new HashMap<String,LabeledBox>(); createInteractors(); addActionListeners(); addMouseListeners(); } /* Creates the control strip at the bottom of the window */ private void createInteractors() { nameField = new JTextField(MAX_NAME); nameField.addActionListener(this); addButton = new JButton("Add"); removeButton = new JButton("Remove");...
View Full Document

Page1 / 3

34a-section-6-solutions - Handout#34A CS 106A Aug 4 2009...

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

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