The following code displays a digital clock within a panel: public class ClockPanel extends JPanel { public void paintComponent(Graphics g) { final int hoursInDay = 12; final int minutesInHour = 60;...



The following code displays a digital clock within a panel:


public class ClockPanel extends JPanel


{


public void paintComponent(Graphics g)


{


final int hoursInDay = 12;


final int minutesInHour = 60;


// Draw the enclosing rectangle


g.drawRect(20, 20, 345, 140);


// Get random hour and minute


Random generator = new Random();


int hour = generator.nextInt(hoursInDay + 1);


int minute = generator.nextInt(minutesInHour + 1);


// Display the time


g.setFont(new Font("Monospaced", Font.BOLD, 50));


g.drawString(hour + ":" + minute, 150, 100);


} // end paintComponent


} // end ClockPanel


Divide this code into two general classes, DigitalClock and DigitalClockPanel. The class DigitalClock defines data fields to represent the time, the position of the clock, and the color of the font to draw the time. The class should have only a default constructor that sets the clock’s


• Time to the current time


• Position to the coordinates (20, 20)


• Width and height to 345 and 140, respectively


• Font color to blue


The class DigitalClockPanel should contain all the necessary methods to create an instance of DigitalClock and paint it on the panel. Provide a test driver that creates one instance of DigitalClockPanel centered within a frame.



May 18, 2022
SOLUTION.PDF

Get Answer To This Question

Submit New Assignment

Copy and Paste Your Assignment Here