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 Java and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.
- Convert time from 24 hour clock to 12 hour clock format
- 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
- Java 8 Clock instant() method with Examples
- Java 8 Clock hashCode() method with Examples
- Java 8 Clock getZone() method with Examples
- Java 8 Clock fixed() method with Examples
- Java 8 Clock millis() Method with Examples
- Java 8 Clock equals() Method with Examples
- Java 8 Clock offset() method with Examples
- Clock tick() Method in Java with Examples
- Clock tickSeconds() method in Java with Examples
- Clock systemDefaultZone() Method in Java with Examples
- Clock systemUTC() Method in Java with Examples
- Clock system() Method in Java with Examples
- Java Applet | How to display a Digital Clock
- Java Applet | How to display an Analog Clock
- HijrahChronology dateNow(Clock) method in Java with Example
- HijrahDate now(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 firstname.lastname@example.org. 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.