Another Custom Canvas: A Thermometer
A custom canvas that displays a
thermometer.
A
driver that demonstrates how it works.
This is the
output produced.
Some things to note:
- The setters and construtors verification of displayable data for the
temperature.
- The drawing of the thermometer relative to the size of the canvas on
which it is diplayed.
- the use of the class Font and the methods setFont() and
the use of the class FontMetrics and the method
getFontMetrics() determine the string width via the method
stringWidth() to center the thermometer title.
- Note that the outline of the thermometer is drawn afer the stalk
and the bulb are filled. If drawn first, the filling would draw over
the outlines.