Question
Asked Oct 18, 2019

java write a app that prompts the user for the number of miles and outputs the conversion to kilometers. Get input from the user by creating an input form at the top of the UI

check_circleExpert Solution
Step 1

Program Description

  • A java JavaX application is written which accepts user input in miles and displays the output in kilometers.
  • A support function is designed which is called by button click event and it converts the miles to kilometers.
  • A UI is designed using GridPane and two text fields and a button.
Step 2

Java Program

import javafx.application.Application;

import javafx.geometry.Pos;

import javafx.geometry.HPos;

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;

 

public class MilesToKMCalculator extends Application {

     //declare UI variables to accept user input and

     //and display output value

     private TextField tfMiles = new TextField();

     private TextField tfKilometers = new TextField();

     private Button btCalculate = new Button("Calculate");

 

     @Override

// Override the start method in the Application class

     public void start(Stage primaryStage) {

           // Create UI

           GridPane gridPane = new GridPane();

           gridPane.setHgap(2);

           gridPane.setVgap(3);

           gridPane.add(new Label("Miles:"), 0, 0);

           gridPane.add(tfMiles, 1, 0);

           gridPane.add(new Label("Kilometers:"), 0, 1);

           gridPane.add(tfKilometers, 1, 1);

           gridPane.add(btCalculate, 1, 3);

           // Set properties for UI

           gridPane.setAlignment(Pos.CENTER);

           tfMiles.setAlignment(Pos.BOTTOM_RIGHT);

           tfKilometers.setAlignment(Pos.BOTTOM_RIGHT);

           tfKilometers.setEditable(false);

&n...

Want to see the full answer?

See Solution

Check out a sample Q&A here.

Want to see this answer and more?

Solutions are written by subject experts who are available 24/7. Questions are typically answered within 1 hour*

See Solution
*Response times may vary by subject and question
Tagged in

Engineering

Computer Science

Java

Related Computer Science Q&A

Find answers to questions asked by student like you

Show more Q&A add
question_answer

Q: Linux servers 1. Cceate FOLDERNAME, script that gven a will create dinectocy named dircetory, and Su...

A: Open Linux editor using command "vi newclass.sh".To enter input in the empty editor with name newcla...

question_answer

Q: How would I go about writing the code in the problem in the picture?

A: Program AlgorithmCreate a class Prime_Numbers and define the main() function.Initialize the required...

question_answer

Q: Create a program that prompts the user for an amount less than 100 and then displays the minimum num...

A: Program AlgorithmInitialize the required variables.Get the input from the user and check if the inpu...

question_answer

Q: (check all that apply) The ER model for a small bank system has Customer, Account, CheckingAccount, ...

A: The answer is option D - Employees and their supervisors.

question_answer

Q: Assume you are writing code to maintain a linked list. You are to usea variable named head to always...

A: Create a class with name Linked_list and the within that class create rest of the classes a static t...

question_answer

Q: I need help with this C++ problem.    Assume that a binary search function is searching for a value ...

A: Binary search: - It is a technique used to search an element in a sorted array.It is also known as h...

question_answer

Q: I have to code the game mastermind, but i only got halfway. I got the user input, 8 colors and the 3...

A:  solving the duplication problem:Create a temporary array named "temp" and initiate that array with ...

question_answer

Q: Show that xz = (x + y)(x + ~y)(~x + z) Using Truth Tables Using Boolean identities

A: 1.Answer: xz = (x + y) (x + ~y) (~x + z)LHS = xzRHS = (x + y) (x + ~y) (~x + z)1. Truth Table: 

question_answer

Q: I am working on Python. I have been asked to write a program for this question. Write a program that...

A: The below source code will take the input from the user as many times as the user wants until the us...