Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

( java code but do NOT make java fx , it cant be a java fx code and I am using BlueJ ) Use Chapter

( java code but do NOT make java fx, it cant be a java fx code and I am using BlueJ )
Use Chapter 11 Kilometer Converter application code (Section 11.7) to write Temperature Converter application to convert degrees Fahrenheit into degrees Celsius ((F -32)*5/9). Use a lambda expression. Below is the application code for the kilometer Converter.
import javafx.application.Application;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.geometry.Pos;
import javafx.geometry.Insets;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.control.Button;
import javafx.event.EventHandler;
import javafx.event.ActionEvent;
/**
* Kilometer Converter application
*/
public class KiloConverter extends Application
{
// Fields
private TextField kiloTextField;
private Label resultLabel;
public static void main(String[] args)
{
// Launch the application.
launch(args);
}
@Override
public void start(Stage primaryStage)
{
// Create a Label to display a prompt.
Label promptLabel = new Label("Enter a distance in kilometers:");
// Create a TextField for input.
kiloTextField = new TextField();
// Create a Button to perform the conversion.
Button calcButton = new Button("Convert");
// Register the event handler.
calcButton.setOnAction(new CalcButtonHandler());
// Create an empty Label to display the result.
resultLabel = new Label();
// Put the promptLabel and the kiloTextField in an HBox.
HBox hbox = new HBox(10, promptLabel, kiloTextField);
// Put the HBox, calcButton, and resultLabel in a VBox.
VBox vbox = new VBox(10, hbox, calcButton, resultLabel);
// Set the VBox's alignment to center.
vbox.setAlignment(Pos.CENTER);
// Set the VBox's padding to 10 pixels.
vbox.setPadding(new Insets(10));
// Create a Scene.
Scene scene = new Scene(vbox);
// Add the Scene to the Stage.
primaryStage.setScene(scene);
// Set the stage title.
primaryStage.setTitle("Kilometer Converter");
// Show the window.
primaryStage.show();
}
/*
* Event handler class for calcButton
*/
class CalcButtonHandler implements EventHandler
{
@Override
public void handle(ActionEvent event)
{
// Get the kilometers.
Double kilometers = Double.parseDouble(kiloTextField.getText());
// Convert the kilometers to miles.
Double miles = kilometers *0.6214;
// Display the results.
resultLabel.setText(String.format("%,.2f miles", miles));
}
}
}

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

Database Concepts

Authors: David M Kroenke, David J Auer

6th Edition

0132742926, 978-0132742924

More Books

Students also viewed these Databases questions

Question

Discuss all branches of science

Answered: 1 week ago

Question

Refine your chart to communicate efficiently and effectively.

Answered: 1 week ago

Question

Choose the best chart for your dataset.

Answered: 1 week ago