Question

Use Kilometer Converter application code to write Temperature Converter application to convert degrees Fahrenheit into degrees Celsius ((F - 32)*5/9). It needs to be JavaFX
1 import javafx.application. Application; 2 import javafx.stage. Stage; 3 import javafx.scene. Scene; 4 import javafx.scene.l
w 25 26 // Launch the application. 27 launch(args); 28 w 29 30 @Override
31 public void start (Stage primaryStage) 32 { 33 // Create a Label to display a prompt. 34 Label promptLabel = new Label (E
57 // Set the VBoxs padding to 10 pixels. vbox.setPadding (new Insets (10)); 58 59 60 // Create a Scene.
61 Scene scene = new Scene (vbox); 62 63 // Add the Scene to the Stage. 64 primaryStage.setScene (scene); 65 66 // Set the st85 // Convert the kilometers to miles. 86 double miles = kilometers * 0.6214; 87 88 // Display the results. 89 resultLabel.se

0 0
Add a comment Improve this question Transcribed image text
Answer #1
import javafx.applications.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;

/**
 * Temperature Converter application
 */

public class TemperatureConverter extends Application
{
    // Fields
    private TextField farenheitTextField;
    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 temperature in farenheit:");

        // Creeate a TextField for input.
        farenheitTextField = new TextField();
        
        // Create a Button to perform the conversion.
        Button calcButtton = new Button("Convert");
        
        // Register the event handler.
        calcButtton.setOnAction(new CalcButtonHandler());
        
        // Create an empty Label to display the result.
        resultLabel = new Label();
        
        // Put the promptLabel and the farenheitTextField in an HBox.
        Hbox hbox = new HBox(10, promptLabel, farenheitTextField);
        
        // Put the HBox, calcButton and the 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("Kilo ");
        
        // Show the window.
        primaryStage.show();
    }

    /*
    * Event handler class for calcButton
    */

    class CalcButtonHandler implements EventHandler<ActionEvent>
    {
        @Override
        public void handle(ActionEvent event)
        {
            // Get the Fahrenheit.
            double fahrenheit = Double.parseDouble(farenheitTextField.getText());

            // Conver the fahrenheit to celsius.
            double celsius = ((fahrenheit - 32) * 5 / 9);
 
            // Display the results.
            resultLabel.setText(String.format("%,.2f celsius", celsius));
        }
    }
}
Add a comment
Know the answer?
Add Answer to:
Use Kilometer Converter application code to write Temperature Converter application to convert degrees Fahrenheit into degrees...
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
  • 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) { //...

  • (5 points) Analyze the following codes. b) import javafx.application.Application; import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.scene.Scene; import...

    (5 points) Analyze the following codes. b) import javafx.application.Application; import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.layout.HBox; import javafx.stage.Stage; public class Test extends Application { @Override // Override the start method in the Application class public void start(Stage primaryStage) { Button btOK = new Button("OK"); Button btCancel = new Button("Cancel"); EventHandler<ActionEvent> handler = new EventHandler<ActionEvent>() { public void handle(ActionEvent e) { System.out.println("The OK button is clicked"); } }; btOK.setOnAction(handler); btCancel.setOnAction(handler); HBox pane = new HBox(5); pane.getChildren().addAll(btOK, btCancel); Scene...

  • Examine the following code and complete missing parts: import javafx.application.Application; import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.geometry.Insets;...

    Examine the following code and complete missing parts: import javafx.application.Application; import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.geometry.Insets; import javafx.geometry.Pos; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.Label; import javafx.scene.control.TextField; import javafx.scene.layout.HBox; import javafx.scene.layout.VBox; import javafx.stage.Stage; public class NtoThePowerOfN extends Application{ @Override public void start(Stage primaryStage) throws Exception { TextField inputField; TextField outputField; VBox base = new VBox(10); base.setPadding(new Insets(10)); base.setAlignment(Pos.CENTER); // // A: input components - label and text field // // // B: button - to compute the value // // //...

  • This is my code. I need the UML for this code My code: public class Main...

    This is my code. I need the UML for this code My code: public class Main extends FlightManager {    Stage window;    Scene scene;    Button button;    HBox layout = new HBox(20);    Label dateTxt, airlineTxt, originTxt, destTxt, clssTxt, scopeTxt, adultsTxt, childTxt;    @Override public void start(Stage stage) { // create the UI and show it here    window = stage; window.setTitle("Reservations 2020"); button = new Button("New Flight");    VBox group3 = new VBox(10); dateTxt = Text("", group3);...

  • A game clock that starts at zero and begins to count up in seconds. Add buttons...

    A game clock that starts at zero and begins to count up in seconds. Add buttons to pause and resume the clock. Given this initial code: import javafx.animation.KeyFrame; import javafx.animation.Timeline; import javafx.application.Application; import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.geometry.Pos; import javafx.scene.Scene; import javafx.scene.control.Label; import javafx.stage.Stage; import javafx.util.Duration; import javafx.scene.paint.Color; public class AnimationCounter2 extends Application{ @Override public void start(Stage stage) throws Exception{ // Create the label and align its contents. Label label = new Label("0"); label.setTextFill(Color.RED); label.setStyle("-fx-font-size: 4em;"); label.setAlignment(Pos.CENTER); EventHandler<ActionEvent> handler =...

  • / Finish the code to make it work import static javafx.application.Application.launch; import java.io.File; import javafx.application.Application; import...

    / Finish the code to make it work import static javafx.application.Application.launch; import java.io.File; import javafx.application.Application; import javafx.event.ActionEvent; import javafx.geometry.Insets; import javafx.geometry.Pos; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.ChoiceBox; import javafx.scene.control.Label; import javafx.scene.layout.HBox; import javafx.scene.layout.VBox; import javafx.scene.media.AudioClip; import javafx.stage.Stage; public class JukeBox extends Application { private ChoiceBox<String> choice; private AudioClip[] tunes; private AudioClip current; private Button playButton, stopButton;    //----------------------- // presents an interface that allows the user to select and play // a tune from a drop down box //-----------------------   ...

  • Intro to Java - Assignment JAVA ASSIGNMENT 13 - Object Methods During Event Handling Assignment 13...

    Intro to Java - Assignment JAVA ASSIGNMENT 13 - Object Methods During Event Handling Assignment 13 Assignment 13 Preparation This assignment will focus on the use of object methods during event handling. Assignment 13 Assignment 13 Submission Follow the directions below to submit Assignment 13: This assignment will be a modification of the Assignment 12 program (see EncryptionApplication11.java below). Replace the use of String concatenation operations in the methods with StringBuilder or StringBuffer objects and their methods. EncryptTextMethods.java ====================== package...

  • You may adjust the code as you want. Thank you! CODING HERE: import javafx.application.Application; import javafx.event.*;...

    You may adjust the code as you want. Thank you! CODING HERE: import javafx.application.Application; import javafx.event.*; import javafx.scene.*; import javafx.scene.control.*; import javafx.scene.layout.*; import javafx.stage.*; import javafx.geometry.*; public class OrderSystem extends Application implements EventHandler<ActionEvent> { // Attributes for GUI private Stage stage; // The entire window, including title bar and borders private Scene scene; // Interior of window private BorderPane layout; // Add four labels private Label itemLabel = new Label("Item Name:"); private Label numberLabel = new Label("Number:"); private Label costLabel...

  • JavaFX! Just need to fill several lanes of code please!!! CSE205 OOP and Data Structure Quiz #15 Last Name (print) First Name (print) Write a JavaFX GUI application program that simulates a timer. T...

    JavaFX! Just need to fill several lanes of code please!!! CSE205 OOP and Data Structure Quiz #15 Last Name (print) First Name (print) Write a JavaFX GUI application program that simulates a timer. The timer should show "count: the beginning and increase the number by 1 in every one second, and so on. o" at .3 A Timer - × A Timer Count: 0 Count: 1 (B) After 1 second, the GUI Window (A) Initial GUI Window According to the...

  • For this question you will need to complete the methods to create a JavaFX GUI application...

    For this question you will need to complete the methods to create a JavaFX GUI application that implements two String analysis algorithms. Each algorithm is activated when its associated button is pressed. They both take their input from the text typed by the user in a TextField and they both display their output via a Text component at the bottom of the GUI, which is initialized to “Choose a string methods as indicated in the partially completed class shown after...

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