0% found this document useful (0 votes)
13 views

Lab 2

The document provides instructions for developing an analog clock applet in Java using multiple threads. It explains that one thread should handle calculations to determine clock hand positions, while another thread handles drawing with the paint() method. The calculation thread gets clock hand positions from shared memory and signals the applet to redraw every second. Minimum requirements include not using deprecated functions, terminating threads properly, delegating calculations to threads, and accepting a width parameter. Resources are provided to help with line rotation and translation without using deprecated date functions.

Uploaded by

Mohammad Rizwan
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

Lab 2

The document provides instructions for developing an analog clock applet in Java using multiple threads. It explains that one thread should handle calculations to determine clock hand positions, while another thread handles drawing with the paint() method. The calculation thread gets clock hand positions from shared memory and signals the applet to redraw every second. Minimum requirements include not using deprecated functions, terminating threads properly, delegating calculations to threads, and accepting a width parameter. Resources are provided to help with line rotation and translation without using deprecated date functions.

Uploaded by

Mohammad Rizwan
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

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
http://www.cs.trinity.edu/~jhowland/cs3353/intro/intro/
2. Do not use the date class, it has many deprecated functions. Use
Calendar class instead.

You might also like