Answered step by step
Verified Expert Solution
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 Kilometer Converter application code Section to write Temperature Converter application to convert degrees Fahrenheit into degrees Celsius F 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 mainString args
Launch the application.
launchargs;
@Override
public void startStage primaryStage
Create a Label to display a prompt.
Label promptLabel new LabelEnter a distance in kilometers:";
Create a TextField for input.
kiloTextField new TextField;
Create a Button to perform the conversion.
Button calcButton new ButtonConvert;
Register the event handler.
calcButton.setOnActionnew 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 promptLabel, kiloTextField;
Put the HBox, calcButton, and resultLabel in a VBox.
VBox vbox new VBox hbox, calcButton, resultLabel;
Set the VBox's alignment to center.
vbox.setAlignmentPosCENTER;
Set the VBox's padding to pixels.
vbox.setPaddingnew Insets;
Create a Scene.
Scene scene new Scenevbox;
Add the Scene to the Stage.
primaryStage.setScenescene;
Set the stage title.
primaryStage.setTitleKilometer Converter";
Show the window.
primaryStage.show;
Event handler class for calcButton
class CalcButtonHandler implements EventHandler
@Override
public void handleActionEvent event
Get the kilometers.
Double kilometers Double.parseDoublekiloTextFieldgetText;
Convert the kilometers to miles.
Double miles kilometers ;
Display the results.
resultLabel.setTextStringformatf miles", miles;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started