Computer Science 120
Introduction to Programming

Spring 2012, Siena College

Lab 8: Drawing Dots
Due: the start of your next lab session

Your task this week is to implement a very simple drawing program. The extent of its capabilities are to draw dots (FilledOvals) on the canvas in three different sizes and colors, to be able to drag around, change the color of, and delete those dots. You may work alone or with a partner on this lab.

Problem Description

The operation of the program is straightforward. Three drop-down menus located at the bottom of the canvas select the operation and the size and color to be used in that operation. When the user presses the mouse on the canvas, the appropriate action is taken.

A working solution for this program will appear below. Click inside the applet to interact with it.



To help you get started, we have provided a starter BlueJ project with the framework of the program that includes some of the code to do the initial setup, including everything that sets up and manages the drop-down menus, and comments indicating where you should make your changes to complete the program. Unlike recent lab programs, this program is all in one class, and there are no ActiveObjects.

Your primary task is to declare, construct, and manage an ArrayList that will keep track of the dots on the canvas.

Lab Procedure

In addition to this document, please read through the entire DotsList.java file from the starter code.

Some constants and instance variables are provided; you will need to provide more.

The begin method adds the drop-down menus to the bottom of the window. You need not worry about the details here (though you are welcome to look at how these menus are used if you are interested). At the end of the constructor, you will likely need to construct your ArrayList and initialize some instance variables.

The onMousePress method will call one of four methods, depending on which of the four options is selected in the first drop-down menu. You may or may not need to add any additional code to onMousePress.

The four methods called by onMousePress will form the bulk of your task: addNewDotAt, recolorDotAt, deleteDotAt, and selectDotAt. Be sure to make use of the code commented out in addNewDotAt which selects the appropriate size based on the middle drop-down menu. Also, a completed version of a getSelectedColor menu is provided: use it! The skeletons of another helper method getIndexOf is also provided. You are not required to implement and use this method, but it is recommended.

Finally, a skeleton of the onMouseDrag method is provided where you will complete the usual object dragging code.

When you start coding, we suggest working on adding a dot first, then recoloring, then selecting (and the corresponding dragging), and finally, deleting. Get one part working before worrying about the next! Important note: you will probably want to implement getIndexOf before moving on to setting colors, dragging, and deleting. It will be of use to you in each of those!

There are no specific extra credit tasks, but you may feel free to propose your own, for up to a total of 4 points.

Submitting Your Work

Before the start of your next lab session, submit your Java program for grading. There are three things you need to do to complete the submission: (i) place a copy of your Java program into your csis120/hw folder under hw12, (ii) print a copy of your program and hand it to your instructor, and (iii) demonstrate the execution of your program for your instructor.

Don't forget to check your programs for compliance with the Style Guide for CSIS 120 Programs

Grading

This assignment is worth 100 points, which are distributed as follows:

> FeatureValueScore
Style, Design, and Efficiency
Appropriate comments 6
Good variable names 4
Appropriate variable declarations 8
Good use of constants 8
Appropriate formatting 2
ArrayList management efficiency 4
Good overall design 8
Correctness
ArrayList declaration and construction 8
Adding new dot 10
Recolor existing dot 10
Drag existing dot 10
Delete existing dot 10
Selection always uses dot "on top" 6
Selected dot moves to top of stacking order 6
Extra Credit
Total 100