Analog Clock Applet
Last Day of Submission: 23 Feb 2011. 11:59 PM
Today's task aims to show you how Java threads are used. You will
develop an applet that will display an analog clock like this.
Paint function is called every time the applet is redrawn on the
screen. Best way to develop graphical application is by separating
the drawing and the calculation functions i.e. one thread does all
the calculations and other thread draws the calculated results.
Shared
Mem
Line Drawing
Calculations Thread. i.e.
Thread paint(...)
Analog Clock: When the Java applet is initialized it spawns a thread
that calculates the location of different clock hands. Paint method
takes this information from the calculation thread via some shared
memory. Here is general algorithm for the calculation thread
Calculation Thread
{
while(running)
calculate the lines positions
put the information in the shared memory
tell the applet to repaint
wait for one sec
}
Paint Method
{
Read Shared Memory
Draw Data
}
Minimum Requirements
1. Do not use any deprecated function in the source code.
2. Make sure that the thread terminates when the applet is closed.
3. Do not directly extend the Thread class.
4. The code should be able to accept a width parameter. Width
defines the width of the clock.
5. Do not do any kind of calculation inside the applet. Delegate
all calculations to one or more threads.
Some Resources That Might Help
1. Please see section 3 and 5 that show how to rotate and translate
a line
[Link]
2. Do not use the date class, it has many deprecated functions. Use
Calendar class instead.