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

  1. The application should be placed in a package named "thermometer".
  2. The application should be invoked as a jar file:
  3.     java -jar thermometer.jar minValue maxValue value
  4. The height of the thermometer's rectangle should be 3/4 the height of the window.
  5. The width of the thermometer's rectangle should be 1/15 the height of the rectangle
  6. The bulb should be 3 times the width of the thermometer.
  7. The labels for the minimum, maximum, and user-specified value should be in bold, 12 point Helvetica font
  8. 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!).
  9. 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.
  10. 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).
  11. The bottommost temperature should start at the following location:
  12.      bottom temperature location = thermometer rectangle's bottom - bulbWidth
  13. You will need to submit four files:
    1. 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.
    2. ThermometerModel.java: An implementation of the model
    3. ThermometerView.java: An implementation of the view
    4. 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.
  14. To submit your program, follow the directions on the homework web page.


Hints

  1. Use the Meter Application presented in class as a guide for your implementation.
  2. drawRect can be used to draw the outline of a rectangle and fillRect and fillOval can be used to create filled rectangles and circles.
  3. 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
  4. 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.