Reference: Chapter 2 of the Swing Tutorial book
and Learning Swing with the NetBeans IDE
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 following the usual steps in creating an application using the IDE, as demonstrated in the "Learning Swing with the NetBeans IDE" tutorial. Alturnatively, you can start with the code that the IDE generates (click on the "example index" link to get a link to that code) and modify the code (probably harder than using IDE). The CelsiusConverter is also described in Example 3 of Chapter 2 of the text (and a previous version of the code is on the CD that comes with that book). The interface should look something like this:
------------------------ | | | ---------------- | | | <textField> | | | ---------------- | | | | ---------------- | | | (*) C to F | | | ---------------- | | | ( ) F to C | | | ---------------- | | ---------------- | | | Convert | | | ---------------- | | | | Fahr temp: 93 | | | ------------------------
When the user clicks on one of the radio buttons to select the
direction of conversion, you could use an action listener to
change a global state variable that indicates which button is
selected. However, this may not be necessary.
In the action listener that responds to a press of the Convert
button, the code could perform the C-to-F or F-to-C conversion
depending on the value of the state variable, or perhaps more easily by just
using the isSelected() method of one (or both) of the
radio buttons to make the decision between which conversion to do.
The formula for conversion from Celsius to Fahrenheit
is given in the tutorial; the reverse formula for converting
Fahrenheit to Celsius is:
tempCelsius = (tempFahr - 32)*5/9
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
components 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,
assignment number, and date)
should be included as comments at the top of your main program file.
11. (4 points) The program listing will be included in the IDE
project that you submit to the class WebDrop.
This listing should show good style (mostly supplied by IDE),
and be appropriately commented.
13. (5 points) The most important part.
Do a demo of your program for the TA that demonstrate that
it works correctly.