Create a temperature 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 temperature. 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 temperature application
The application should be placed in a package named "temperature".
The application should be invoked as a jar file:
java -jar temperature.jar minValue maxValue value
The height of the thermometer's rectangle should be 3/4 the height of the
The width of the thermometer's rectangle should be 1/15 the height of the
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 the following files:
- TemperatureApplication.java: This class will contain the main method
and should: 1) allocate a TemperatureModel object and a
2) link the two objects so they can communicate, and 3) set the
model's temperature to the user-specified value.
TemperatureModel.java: An implementation of the model
Thermometer.java: An implementation of the thermometer
- temperature.jar: A jar file that contains the class files for the
three previous files plus a manifest.txt file that points to
TemperatureApplication as the class containing "main".
The manifest.txt file will need to contain the fully qualified name of
the TemperatureApplication class.
To submit your program, follow the directions on the homework web page.
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.