StillClock class is used to displays an analog clock and uses the MessagePanel to display the hour, minute, and second in a panel. We use javax.swing.JPanel to display the StillClock.
This article helps to develop a class that displays a clock on a panel.
Steps used to draw the clock:
- To draw a clock, draw a circle and three hands for a second, minute and hour.
- One end is the center of the clock at (xCenter, yCenter) and the other end (xEnd, yEnd) is determined by,
xEndpart = yCenter + handLength X sin(0) yEndpart = yCenter + handLength X cos(0)
- The angle for the second hand(Sixty seconds in one minute),
- The angle for the minute hand is,
(minute + second/60)*(2*pi/60)
- Since, one circle is divided into twelve hours, the angle for the hour hand is,
(hour + minute/60 + second/(60*60)) * (2*pi/12)
Below is the implementation of the above approach:
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Android | How to display Analog clock and Digital clock
- Java Clock tickMinutes() method in Java with Examples
- Java Clock withZone() method in Java with Examples
- ThaiBuddhistDate now(Clock) method in Java with Example
- HijrahDate now(Clock) method in Java with Example
- YearMonth now(clock) method in Java with Examples
- Java 8 Clock equals() Method with Examples
- Clock systemUTC() Method in Java with Examples
- Clock system() Method in Java with Examples
- Java 8 Clock offset() method with Examples
- JapaneseDate now(Clock) method in Java with Examples
- Java Applet | How to display an Analog Clock
- Clock systemDefaultZone() Method in Java with Examples
- Java Applet | How to display a Digital Clock
- Clock tickSeconds() method in Java with Examples
- Java 8 Clock millis() Method with Examples
- Clock tick() Method in Java with Examples
- Java 8 Clock fixed() method with Examples
- IsoChronology dateNow(Clock) method in Java with Example
- HijrahChronology dateNow(Clock) method in Java with Example
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.