Question: Create a package called clocks in your csc205 project. Define a Java interface called IClock that has three public int methods called getHour(), getMinute() and
Create a package called clocks in your csc205 project.
Define a Java interface called IClock that has three public int methods called getHour(), getMinute() and getSecond() (Every class that implements the IClock interface has to define these methods)
Define a class called Clock that implements the IClock interface: use the code given below and just write the get methods
package clocks;
* This is a clock that shows local time.
*
* @author (TMR)
* @version (9/17)
import java.util.*; //To use the GregorianCalendar class
import java.text.*;
public class Clock implements IClock
private int second; //current time in hrs, mins and seconds
private int minute;
private int hour;
public Clock()
// The clock gets current time from the GregorianCalendar class
GregorianCalendar date = new GregorianCalendar();
second = date.get(Calendar.SECOND);
minute = date.get(Calendar.MINUTE);
hour = date.get(Calendar.HOUR);
// Write the getHour, getMinute and getSecond methods
Write a ClockTester class that will just have a public static void method that:
Instantiates a Clock object
Get the hours, minutes and seconds using the get methods and print them on the terminal output. Something like this:
Current time is hh hours, mm minutes and ss seconds
Create a javafx class called ClockGUI extends Application in the clocks package with the following specifications. It will just have three labels: hours, minutes and seconds, and three uneditable text fields and a ShowTime Button as shown in the picture below:
Before Button-Click After Button Clock
Use the following template to create your javafx application: (Fill in the blanks). Use the LoanCalculator program as a model.
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.GridPane;
import javafx.stage.Stage;
import javafx.event.EventHandler;
import javafx.event.ActionEvent;
public class ClockGUI extends Application
{
//Declare GUI Components
public static void main(String[] args) {
launch(args);
}
public void createGUIComponents()
{
//Instantiate GUI Components and build GUI
}
public void attachHandlers()
{
showButton.setOnAction(new EventHandler
{
public void handle(ActionEvent e)
{
Clock ck = new Clock();
hoursTF.setText(""+ck.getHour());
minutesTF.setText(""+ck.getMinute());
secondsTF.setText(""+ck.getSecond());
}
});
}
public void start(Stage stage) {
createGUIComponents();
attachHandlers();
Scene scene = new Scene(pane);
stage.setScene(scene);
stage.setTitle("Clocks View");
stage.setWidth(200);
stage.setHeight(150);
stage.show();
}
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
