Computer Science 120
Introduction to Programming

Spring 2011, Siena College

Lab 6: 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.

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 create and manage an array that will keep track of the dots on the canvas.

Lab Procedure

In addition to this document, please read through the entire DrawingProgram.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. At the end of the constructor, you will likely need to construct your array 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! Skeletons of other helper methods are also provided: getIndexOf and removeDotAtIndex that you are not required to implement and use, 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, I recomment 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!

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 hw7, (ii) print a copy of your program and hand it to your lab instructor, and (iii) demonstrate the execution of your program for your instructor.

Grading Sheet

This lab is worth 25 points, which are distributed as follows:

> FeatureValueScore
Style, Design, and Efficiency
Appropriate comments 3
Good variable names and declaration types 2
Appropriate formatting 1
Array management efficiency 2
Good overall design 2
Correctness
Array declaration and construction 2
Adding new dot 3
Recolor existing dot 3
Drag existing dot 3
Delete existing dot 3
Attempted add ignored when array is full 1
Extra Credit
Total 25