Question: Please write an applet to show the analog clock. The clock shape does not need to be a circle. It can be any shape as

Please write an applet to show the analog clock.

The clock shape does not need to be a circle. It can be any shape as long as it shows the time. However, it wont tell you the current time. Unlike the usual clock the arm for sec ticks on every 10 secs. So arm for minutes moves one click per 10 minutes and clock arm moves one click on every 10 hours.

For the sake of test make two buttons to start and stop the clock. You can consider the clock as a stop watch for the planet where the time passes 10 times slower than the time on earth.

Why we are doing this? Clock is one of the important components that OS relies on, further I want you to use and understand the sleep, suspend, wake, etc.

If your digital clock shows C sec,

Calculate secX(x coordinates for arm for sec and secY as follows;

secX = (int) (CPX + LM*(Math.sin(2*Math.PI*(C/60.0))));

secY = (int) (CPY - LM*(Math.cos(2*Math.PI*(C/60.0))));

where CPX means center of clock positions x coordinates,

CPY means center of clock positions y coordinates,

Then draw line from (CPX, CPY) to (sexX, sexy) as an arm for sec.

For example, if the clock is placed within the box (10, 60, 150, 150)

Meaning left top corner coordination is (10, 60),

With and length are 150 and the center coordination is (85, 135)

Then the secX amd secY can be calculated by

secX = (int) (85 + 70*(Math.sin(2*Math.PI*(secC/60.0))));

secY = (int) (135 -70*(Math.cos(2*Math.PI*(secC/60.0))));

the actual arm can be drawed by

drawline(85,135,secX,secY)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!