GCIS 501
Fall 2009
Lab 5
Summary
You are to develop a Java application that will ask the user for the time in terms of hour
and minutes and display the time by drawing a clock (see the sample output on the last
page).
Designing a Solution
To draw a clock and its attributes (face, hands, etc.) you will use another of Java’s built in
classes: the
Graphics
class.
To draw a clock hand, you use the
drawLine()
method
of the
Graphics
class.
The endpoints of the line are determined as:
The value for the variable
K
determines the length of the clock hand.
Make the
K
larger
for the minute hand than for the hour hand.
You may have to experiment a bit to get the
proper value for K.
The angle
θ
is expressed in radians.
The angle
θ
min
of the minute
hand is computed as:
(90.0 – Minute * 6.0) *(
π
/180.0)
and the angle
θ
hr
of the hour hand is computed as:
(90.0 – (Hour + Minute/60.0) * 30.0) * (
π
/180.0)
where Hour and Minute are input values.
The values 6.0 and 30.0 designate the degrees
for one minute and one hour (i.e., the minute had moves 6 degrees in one minute and the
hour had moves 30 degrees in one hour).
The factor (
π
/180.0) converts a degree value
into the radian equivalent.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
You can draw the clock on a window by getting the window’s
Graphic
object.
Make sure
the window is visible on the screen before calling its
getGraphic
method.
Your clock
should resemble the sample output.
It should be centered in your window and be
approximately the same size.
Make sure that you include the 12, 3, 6, and 9 o’clock
numbers (more if you would like, but not less).
This is the end of the preview.
Sign up
to
access the rest of the document.
 Fall '09
 Liu
 ObjectOriented Programming, Subroutine, upper left corner

Click to edit the document details