Question

Problem 2) Convert Kilometers to Miles Write a JavaFX program using JavaFX Menu for to solve the following problem about converting between Kilometers to Miles. Sample Run is shown below You are asked to implement only the menu item under Formulas which reads asKM to Mile. Choosing this menu item will display the following input box: Input Enter Kilometers Value OK Cancel The result will be displayed in a TextArea as shown below: JavaF× Menu Example File Formulas 10.0 Kiloneters is equal to 6.241 Miles

java programming

0 0
Add a comment Improve this question Transcribed image text
Answer #1

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Menu;
import javafx.scene.control.MenuBar;
import javafx.scene.control.MenuItem;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextInputDialog;
import java.util.Optional;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;

public class MenuApp extends Application {

public static void main(String[] args) {
launch(args);
}

@Override
public void start(Stage stage) {
stage.setTitle("JavaFX Menu Example");
//adding submenus to menu. Adding menu to menubar
Menu menu1 = new Menu("File");
Menu menu2=new Menu("Formulas");
MenuItem menuItem1 = new MenuItem("KM to Mile");
menu2.getItems().add(menuItem1);
MenuBar menuBar = new MenuBar();
menuBar.getMenus().add(menu1);
menuBar.getMenus().add(menu2);
TextArea result = new TextArea();
VBox vBox = new VBox();
vBox.getChildren().add(menuBar);
vBox.getChildren().add(result);
//performing action when clicking on menu item
menuItem1.setOnAction(e -> {
TextInputDialog input = new TextInputDialog();
input.setTitle("Input");
input.setContentText("Enter Kilometers Value");
// get the response value.
Optional<String> value = input.showAndWait();
if (value.isPresent()){
result.setText(String.format("%.1f Kilometers is equal to %f Miles",Double.parseDouble(value.get()),Double.parseDouble(value.get())*0.621371));
}
});
Scene scene = new Scene(vBox, 960, 200);
stage.setScene(scene);
stage.show();

}
}

Output

Untitled window koushikhp@koushikhpnew: java MenuApp JavaFX Menu Example Input File Formulas Confirmation Enter Kilometers Value Cancel

Add a comment
Know the answer?
Add Answer to:
java programming Problem 2) Convert Kilometers to Miles Write a JavaFX program using JavaFX Menu for...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Java Programming Assignment (JavaFX required). You will modify the SudokuCheckApplication program that is listed below. Start...

    Java Programming Assignment (JavaFX required). You will modify the SudokuCheckApplication program that is listed below. Start with the bolded comment section in the code below. Create a class that will take string input and process it as a multidimensional array You will modify the program to use a multi-dimensional array to check the input text. SudokuCheckApplication.java import javafx.application.*; import javafx.event.*; import javafx.geometry.*; import javafx.scene.*; import javafx.scene.control.*; import javafx.scene.layout.*; import javafx.stage.*; public class SudokuCheckApplication extends Application { public void start(Stage primaryStage)...

  • use this code of converting Km to miles , to create Temperature converter by using java...

    use this code of converting Km to miles , to create Temperature converter by using java FX 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) { //...

  • Need help on following Java GUI problem: Write a program that lets a user display and...

    Need help on following Java GUI problem: Write a program that lets a user display and modify pictures. Create a window. Add four buttons so that clicking a particular button will shift the image by a small amount in the north, south, east or west direction inside the window. Add a menu bar with two menus: File and Image. The File menu should contain an Open menu item that the user can select to display JPEG and PNG files from...

  • Write a Java program to convert octal (integer) numbers into their decimal number equivalents (exactly the...

    Write a Java program to convert octal (integer) numbers into their decimal number equivalents (exactly the opposite of what you have done in Assignment 4). Make sure that you create a new Project and Java class file for this assignment. Your file should be named “Main.java”. You can read about octal-to-decimal number conversions on wikepedia Assignment 4 is at the bottom Objective Your program should prompt the user to enter a number of no greater than 8 digits. If the...

  • PYTHON PROGRAMMING LANGUAGE (NEEDED ASAP) Using a structured approach to writing the program: This section will...

    PYTHON PROGRAMMING LANGUAGE (NEEDED ASAP) Using a structured approach to writing the program: This section will guide you in starting the program in a methodical way. The program will display a window with GUI widgets that are associated with particular functions: Employee Payroll O X -- - - - - - - - - - - Show Payroll Find Employee by Name Highest Lowest Find Employee by Amount Write Output to Fie Cancel - -------- ------------- Notice that some of...

  • Please write it in Java language 2. (Myinterface.java) The program description below was found waaaaay back...

    Please write it in Java language 2. (Myinterface.java) The program description below was found waaaaay back in the archives of the Equinox history database. It is the specification for a simply "computer store storefront". Even though computer stores are now extinct, you find the idea charming and decide to use the specification as inspiration to write an interface for one of the Equinox systems. Read carefully: write your own GUI for one of the Equinox systems, drawing inspiration from the...

  • write a code on .C file Problem Write a C program to implement a banking application...

    write a code on .C file Problem Write a C program to implement a banking application system. The program design must use a main and the below functions only. The program should use the below three text files that contain a set of lines. Sample data of these files are provided with the assessment. Note that you cannot use the library string.h to manipulate string variables. For the file operations and manipulations, you can use only the following functions: fopen(),...

  • could you please help me with this problem, also I need a little text so I...

    could you please help me with this problem, also I need a little text so I can understand how you solved the problem? import java.io.File; import java.util.Scanner; /** * This program lists the files in a directory specified by * the user. The user is asked to type in a directory name. * If the name entered by the user is not a directory, a * message is printed and the program ends. */ public class DirectoryList { public static...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT