Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java Eclipse, just need a ClockTester to this code package lab4Clock; public class ClockTester { public Clock.Clock() { } public static void main(String[]args) { }

Java Eclipse, just need a ClockTester to this code

package lab4Clock;

public class ClockTester

{

public Clock.Clock()

{

}

public static void main(String[]args) {

}

}

//rest of code

package Lab4;

import java.util.Scanner;

class MethodTester

{

public static void main(String args[])

{

Scanner in = new Scanner(System.in);

// Declaration of Object

SomeMethods s = new SomeMethods();

double c;

System.out.println("Enter the values of a and b");

int a = in.nextInt();

int b = in.nextInt();

//call to average method

c = SomeMethods.average(a,b);

System.out.println("The average is" + c);

SomeMethods.countdown(a);

SomeMethods.countdown2(a);

}

}

package lab4Clock;

import java.util.*;

public interface IClock

{

public int getHour();

public int getMinute();

public int getSecond();

}

package lab4Clock;

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

public int getHour()

{

return hour;

}

public int getMinute()

{

return minute;

}

public int getSecond()

{

return second;

}

}

package lab4Clock;

import javafx.geometry.Pos;

import javafx.scene.layout.VBox;

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

protected static Stage pStage;

protected String hours;

protected String minutes;

protected String seconds;

//GUI Components

private VBox pane;

//Labels

private Label hoursLabel;

private Label minutesLabel;

private Label secondsLabel;

private GridPane inputPane;

//text fields

private TextField hoursTF;

private TextField minutesTF;

private TextField secondsTF;

//Buttons

private Button showTimeButton;

private GridPane buttonPane;

public static void main(String[] args) {

launch(args);

}

public void createGUIComponents()

{

//----------------------------------------------------------------

//Create GUI Objects

pane = new VBox(10);

pane.setSpacing(20);

pane.setAlignment(Pos.CENTER);

//----------------------------------------------------------------

//Create Labels

hoursLabel = new Label("Hours");

minutesLabel = new Label("Minutes");

secondsLabel = new Label("Seconds");

//----------------------------------------------------------------

//Create TFs

hoursTF = new TextField();

minutesTF = new TextField();

secondsTF = new TextField();

//----------------------------------------------------------------

// Create GridPane inputPane

inputPane = new GridPane();

inputPane.add(hoursLabel, 0, 0);

inputPane.add(hoursTF, 1, 0);

inputPane.add(minutesLabel, 0, 1);

inputPane.add(minutesTF, 1, 1);

inputPane.add(secondsLabel, 0, 2);

inputPane.add(secondsTF, 1, 2);

//Create Buttons

showTimeButton = new Button("Show Time");

buttonPane = new GridPane();

buttonPane.setHgap(10); //horizontal gap in pixels

buttonPane.setVgap(10); //vertical gap in pixels

buttonPane.setAlignment(Pos.CENTER);

//----------------------------------------------------------------

//buttonPane.setPadding(new Insets(10, 10, 10, 10));

buttonPane.add(showTimeButton, 0, 0);

//----------------------------------------------------------------

//Create handlers for buttons using

//user-defined Handler classes

//showTimeHandler = new ShowTimeHandler();

//----------------------------------------------------------------

//Add the buttons to the pane

pane.getChildren().addAll(inputPane, buttonPane);

}

public void attachHandlers()

{

showTimeButton.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();

}

}

package lab4Clock;

import java.util.*;

public interface IClock

{

public int getHour();

public int getMinute();

public int getSecond();

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Intranet And Web Databases For Dummies

Authors: Paul Litwin

1st Edition

0764502212, 9780764502217

Students also viewed these Databases questions

Question

Explain the function and purpose of the Job Level Table.

Answered: 1 week ago