Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java program of GUI usingJavaFXwithGridPane,TextField,LabelandButtonobjects. This is continuation of Project 7 which used the text-based menu driven model. Write two value-returning methods calledfarToCel()andcelToFar(). These two

Java program of GUI usingJavaFXwithGridPane,TextField,LabelandButtonobjects. This is continuation of Project 7 which used the text-based menu driven model.

Write two value-returning methods calledfarToCel()andcelToFar(). These two methods will convert temperatures from Fahrenheit to Celsius and Celsius to Fahrenheit respectively. They will each take a singleintparameter and return the converted value as anint. (These should already be done and can be taken from Project 7. No other code from Project 7 will be of any consequence.)

Here is a picture of what you will create:

In yourstart()method, do the following:

  • Create two labels "Temperature:" and "Results:" that are centered.
  • Create two text fields with:
  • A maximum width of 200 for each.
  • The temperature text field should be initially set to zero.
  • The results text field has no initial value and should not be an editable field.
  • Create two buttons "Celsius to Fahrenheit" and "Fahrenheit to Celsius". The right-hand button should be right-aligned
  • Set the window title to "Celsius and Fahrenheit Conversion"
  • Set the layout to the GridPane layout. Make the hgap and vgap values 10.
  • Add the temperature label and text field.
  • Add the buttons.
  • Add the result label and text field.
  • Assign the button handlers using the Lambda Expression method.
  • Set the window size to 500 pixels wide by 200 pixels high.

For the button handlers you should perform the following:

  • Read the temperature text field value.
  • Convert the String temperature to an integer.
  • Convert the temperature from one scale to the other.
  • Display the relative information in the results text field.

I am also asked to read thetry/catch.

And this is the example I will retrieve my code from this template below:

 import javafx.application.Application; import javafx.stage.Stage; import javafx.scene.Scene; import javafx.scene.text.TextAlignment; import javafx.scene.control.Label; import javafx.scene.control.TextField; import javafx.scene.control.Button; import javafx.scene.layout.GridPane; //import javafx.event.EventHandler; import javafx.geometry.Pos; import javafx.geometry.HPos; public class Project8_template extends Application { public static int cel2far(int c) { return c * 9 / 5 + 32; } public static int far2cel(int f) { return ( f - 32 ) * 5 / 9; } @Override public void start(Stage primaryStage) { Label l1, l2; TextField tf1, tf2; Button b1, b2; GridPane pane = new GridPane(); Scene scene = new Scene(pane, 500, 200); b1.setOnAction( event -> { // button work goes here. }); /* If you are doing 8a, with two buttons, this is for the second button. b2.setOnAction ( event -> { // button work goes here. }); */ System.out.println(pane); primaryStage.setTitle("Temperature Conversion"); primaryStage.setScene(scene); primaryStage.show(); } public static void main(String[] args) { launch(args); } } 

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_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

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

Get Started

Students also viewed these Programming questions

Question

4. Why is time consistency important in economic models?

Answered: 1 week ago