Announcement (posted 1/24): I have modified the list of files that you
must submit with this assignment. You can put all your code into a single
file named Thermometer.java and then jar up that one file. If you already
started the assignment and are using the MVC model, that is fine. However,
since we will not discuss the MVC model until Tuesday, it is not necessary
to use it in this assignment.
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:
- Thermometer.java: An implementation of the thermometer
- temperature.jar: A jar file that contains the class file for
Thermometer.java plus a manifest.txt file that points to
Thermometer as the class containing "main".
The manifest.txt file will need to contain the fully qualified name of
the Temperature class.
Use the Slider Application presented on the
code webpage class as a guide for your implementation. You do not
have to separate your code into a model and graphical view as is done in
the demo code. It's fine to bundle everything into one file. You will
get practice with the Model View Controller model later in the course.
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.