Lab Assignment 2 -- Demo and Writeup Due 6 p.m. Sept. 25 in the lab session
CS 5551, Fall Semester, 2006
10 Points
Topics: Introduction to Java interfaces - Part II

Reference: Chapter 2 of the Swing Tutorial book

The assignment: Make an enhanced temperature converter that converts either from Celsius to Fahrenheit or from Fahrenheit to Celsius. This can probably be most easily done by modifying the VoteDialog code for Example 6 of Chapter 2. It can be downloaded from: VoteDialog.java.
The interface should look something like this:

------------------------
|                      |
|   ----------------   |
|   | <textField>  |   |
|   ----------------   |
|                      |
|   ----------------   |
|   | (*) C to F   |   |
|   ----------------   |
|   | ( ) F to C   |   |
|   ----------------   |
|   ----------------   |
|   |   Convert    |   |
|   ----------------   |
|                      |
|   Fahr temp: 93      |
|                      |
------------------------

There are four parts to the interface (from top to bottom): a text field to get the input, a radiobox with two buttons to choose which conversion to make, a button that causes the conversion to be performed, and a label to display the results.

Discussion:
The biggest change from VoteDialog is that you don't have to worry about dialogs. This will make the code for actionPerformed() much simpler. The other changes would include:

(1) replacing the title JLabel with a JTextField, which I also had to declare above VoteDialog (to make it "visible to the actionPerformed() function below).

(2) changing the radiobox from 4 buttons to 2 and changing their labels (you might also want to give the ActionCommands more meaningful names).

(3) changing the label on the "Vote" button to "Convert" (trivial).

(4) changing what the actionPerformed() method does. This can be done by modifying the existing code (ignoring all the dialog stuff). The default should be to convert from Celsius to Fahrenheit, and the code can be very similar to that in the CelsiusConverter program: get the current text from the text field widget and convert its value to Fahrenheit (using the conversion formula code in CelsiusConverter), then setting the text of the label at the bottom to something like:
        Converted Temp: 93°F

The case for conversion from Fahrenheit to Celsius can be handled similarly, recalling the formula for converting Fahrenheit to Celsius:
        tempCelsius = (tempFahr - 32)*5/9

(5) changing the names of the variables to be more meaningful for this application.

Extra Enhancements:
There may be a better or more natural way to lay out the interface (maybe using a grid layout). Also wording on the labels on the widgets could probably be improved.

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.
11. (4 points) Include the program listing. This listing should show good style, be appropriately commented, have the important parts highlighted, and include handwritten explanations if it helps the reader's understanding of the code.
13. (5 points) The most important part. Do demos of your modified program for the TA that demonstrate that the program works correctly.


Page URL: http://www.d.umn.edu /~ddunham/cs5551f06/assignments/lab2/assignment.html
Page Author: Doug Dunham
Last Modified: Monday, 11-Sep-2006 16:26:26 CDT
Comments to: ddunham@d.umn.edu