CSC-112 – HW10 Set Clock Time and Animate

Due: Tuesday,  April 16 11:59pm

Write a program that displays a clock and sets the time with the input from three text fields, as shown in the diagram. Note: Pressing ENTER on a textfield generates an ActionEvent. Use the ClockPane in Listing 14.21. On entering data in the textfields, pressing Enter will immediately stop a running clock and display the time shown in the text boxes.

Add 4 additional buttons:

  • A “Start” button that starts a stopped clock
  • A “Stop” button that stops a running clock
  • A “Load Current Time & Start” button that loads the current time and immediately starts the clock
  • A “Just Load Current Time” button the just loads the current time, but doesn’t start the clock.

Place these buttons at the top of the GUI.

Make sure you handle appropriately bad data input.  Also, be sure that the textboxes reflect the state of the analog clock. If the clock changes state, the textboxes reflect that change,  If the textboxes change values, the analog clock displays these values.

Image of Application Described

You might want to add this code to the ClockPane to simplify the ticking of the clock:

public void tick() {
   this.second++;
   if (this.second >= 60) {
     this.second = 0;
     this.minute++;
     if (this.minute >= 60) {
       this.minute = 0;
       this.hour++;
       if (this.hour >= 13)
         this.hour %= 12;
     }
   }
 }