Question
Do not implement a moving clock and do not use threads Language: JAVA Program: Design and implement a class AnalogClock that takes a point of
Do not implement a moving clock and do not use threads Language: JAVA
Program: Design and implement a class AnalogClock that takes a point of reference on the drawing canvas (i.e. coordinates of the upper left corner) and the hours and minutes to display. This AnalogClock class must have an instance method so that the clock can draw itself on a JComponent using the Graphics2D. There should be a square drawn around the clock. Design and implement another class DigitalClock that takes a point of reference on the drawing canvas (i.e. coordinates of the upper left corner) and the hours and minutes to print graphically. This DigitalClock class must also have an instance method so that the digits can be drawn on a JComponent using the Graphics2D. There should be a rectangle drawn around the digits. The DigitalClock can either be drawn at the center of the AnalogClock (the following left frame image) or on the bottom of the AnalogClock (right image).
About your implementation: Create a class that extend the JComponent class and paint on it. This extended JComponent, e.g. ClockComponent, must have two constructors. If the ClockComponents no-arguments constructor is invoked, the current time is used to display the hours and minutes in the clocks. The other ClockComponents constructor is to take two arguments corresponding to the hours and minutes to display in the clocks. Provide a FrameViewer class that has the main method. Ask the user for the time to display (the user should be able to enter the hours and minutes) or let the user choose to display the current time. Add the extended JComponent to a JFrame in the FrameViewer.
When asking the user for the hours and minutes to display, you can assume that the input is numeric (HH:MM) for this assignment, you dont need to do a lot of error checking when entering the time.
Allow for the clock to remain in the middle of the window (frame), when the user resizes the window.
You can use the class java.time.LocalTime to obtain the current time.
Simple Clock Simple Clock 12,40 12:40 Simple Clock Simple Clock 12,40 12:40
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started