Homework 1
Thermometer Application
Create a thermometer application that produces a drawing that looks
like a mercury thermometer . The thermometer 's value should be based on
a value input by the user. The user should also input a minimum and maximum
value for the thermometer. Two example screen shots appear below (the mercury
should be in red, not blue--for some reason when I take screen snapshots
the mercury ends up looking blue rather than red):
Specifications for the thermometer application
-
The application should be placed in a package named "thermometer".
-
The application should be invoked as a jar file:
java -jar thermometer.jar minValue maxValue value
-
The height of the thermometer's rectangle should be 3/4 the height of the
window.
-
The width of the thermometer's rectangle should be 1/15 the height of the
rectangle
-
The bulb should be 3 times the width of the thermometer.
-
The labels for the minimum, maximum, and user-specified value should be
in bold, 12 point Helvetica font
-
The labels should be centered vertically with respect to the temperature
that they display and should be offset 5 pixels from the sides of the thermometer
(do not hard-code 5 wherever you need to use it--use a constant instead!).
-
The thermometer should be centered horizontally in the window. To simplify
the assignment, the thermometer's rectangle should be centered vertically
within the window and the bulb should be tacked onto the bottom by centering
the bulb at the bottom of the thermometer's rectangle. That is why the
thermometer does not appear centered in the two windows.
-
There should be a horizontal line showing where the bottommost temperature
range of the thermometer begins (that would be the horizontal line next
to the 0 in the above screen snapshots).
-
The bottommost temperature should start at the following location:
bottom temperature location = thermometer rectangle's bottom - bulbWidth
-
You will need to submit four files:
- ThermometerApplication.java: This class will contain the main method
and should: 1) allocate a ThermometerModel and a ThermometerView,
2) link the two objects so they can communicate, and 3) set the
model's temperature to the user-specified value.
-
ThermometerModel.java: An implementation of the model
-
ThermometerView.java: An implementation of the view
- thermometer.jar: A jar file that contains the class files for the
three previous files plus a manifest.txt file that points to
ThermometerApplication as the class containing "main".
The manifest.txt file will need to contain the fully qualified name of
the ThermometerApplication class.
-
To submit your program, follow the directions on the homework web page.
Hints
-
Use the Slider Application presented in class as a guide for your implementation.
-
drawRect can be used to draw the outline of a rectangle and fillRect and
fillOval can be used to create filled rectangles and circles.
-
In order to prevent the black outline of the thermometer's rectangle from
enclosing the mercury, you will need to draw both a red-outlined rectangle
and a filled red rectangle
-
Text is drawn at the baseline so if center
represents the vertical center of the text, the text can be vertically
centered by subtracting half of the text's height from center.