Lab Assignment 5 -- Demo and Writeup Due Oct. 10 in the lab session
CS 5551, Fall Semester, 2013
10 Points
Topics: Painting, Radio Buttons / Combo Boxes

Reference: Chapter 6 of the Swing Tutorial book and Radio Buttons or Combo Boxes of Chapter 7

The assignment: Write a program that allows the user to select a rectangular area within a blank area using the mouse. The selected area is then drawn as a filled rectangle in one of three colors: red, green, or blue. The color to be used can be specified by selecting one of three radio buttons (shown below) or by using a combo box. The interface should look something like (assuming that red is the current drawing color):

|            +--------------------------------------+ |
|            |                                      | |
| (*) Red    |                                      | |
|            |                                      | |
| ( ) Green  |           < blank area >             | |
|            |                                      | |
| ( ) Blue   |                                      | |
|            |                                      | |
|            +--------------------------------------+ |
Notes: Useful custom painting code is in the "PaintDemo" files - in particular and . Another, perhaps better example is (which needs the file starfield.gif in an images subdirectory). This program shows how to initialize a rectangle with a mouse press, extend it by "rubberbanding" with a mouse drag, and finalize it with a mouse release. The filled rectangle (rectToDraw) can then be drawn. These program files can be found at Performing Custom Painting: Examples

The RadioButtonDemo program may also be useful. Here is the RadioButtonDemo program file (if you want to actually run it, you need to get the .gif files of the animals - they can be found at: Animal.gif files) . Pressing a radio button could set a global state variable (currentColor ?) that specifies which color is currently being used, or you can iterate through the buttons to find out which one is selected (it is probably a good idea to have one of the buttons selected/set initially).

Extra Enhancements:
1. (1 point) Add a "Filled" toggle button (on top of the Red, Green, Blue buttons, or ..), such that when it is selected the rectangle is drawn as filled, and when de-selected only the unfilled outline is drawn. Here is a sample program that uses a JToggleButton: ScrollDemo prgram files.
2. (1 point) Keep track of the rectangles that have been drawn by the user (up to some maximum number, say 100) and redraw them as needed so that the user can build up a "picture" of different colored rectangles. One way to do this is to make an array of "MyRectangle" objects each of which has Rectangle information and a color (and a filled/unfilled boolean if you did part 1.).
Notes: Extra credit points are usually harder to earn than ordinary points. Also, you should implement the regular assignment features first, before trying to implement any extra credit features. The instructor and TA will be quite generous with their time in helping you debug the regular assignment features, but you should expect to implement the extra credit mostly "on your own".

What to turn in: Turn in the following items from the Computer Science Lab Report Format:
1. (1 point) The Basic Information (your name, class, section, TA's name, assignment number, and date) can be on a separate cover sheet or as (highlighted) comments at the top of your main program file.
9. (up to 2 points if done) Document the Extra Credit part of your program if you did it (by coded/hand-written comments and highlighting -- as usual).
11. (4 points) Include the program listings. This listing should show good style, be appropriately commented, have the important/new parts highlighted, and include handwritten explanations if it helps the reader's understanding of the code.
13./14. (5 points) Do a demo of your modified program for the TA that demonstrates that the program works correctly.

Page URL: /~ddunham/cs5551f13/assignments/lab5/assignment.html
Page Author: Doug Dunham
Last Modified: Wednesday, 02-Oct-2013 17:16:24 CDT
Comments to: