Question: This is my javafx code. I can't rund. I don't know what is wrong. import javafx.application.Application; import javafx.collections.FXCollections; import javafx.collections.ObservableList; import javafx.geometry.HPos; import javafx.geometry.Insets; import

This is my javafx code. I can't rund. I don't know what is wrong.

import javafx.application.Application; import javafx.collections.FXCollections; import javafx.collections.ObservableList; import javafx.geometry.HPos; import javafx.geometry.Insets; import javafx.geometry.Pos; import javafx.scene.Scene; import javafx.scene.control.*; import javafx.scene.layout.ColumnConstraints; import javafx.scene.layout.GridPane; import javafx.scene.layout.Priority; import javafx.scene.text.Font; import javafx.scene.text.FontWeight; import javafx.stage.Stage; import java.awt.*; public class MilesCalculator extends Application { private Label numOfGallonsLabel; private Label numOfMilesLabel; private TextField numOfGallonsTextField; private TextField numOfMilesTextField; private Button calcButton; public static void main(String[] args) {launch();} public void start(Stage primaryStage) throws Exception { primaryStage.setTitle("Miles Per Gallon Calculator for Infiniti"); Font font = Font.font("Arial", FontWeight.BOLD, 12); GridPane gridPane = createRegistrationFormPane(); createLabels(font); createInputFields(); calcButton = new Button("Calculate MPG"); calcButton.setOnAction(e -> calculate()); calcButton.setFont(font); addElements(gridPane); Scene scene = new Scene(gridPane, 300, 580); primaryStage.setScene(scene); primaryStage.show(); } private void createLabels(Font font) { numOfGallonsLabel = new Label("Total number of gallons: "); numOfMilesLabel = new Label("Number of miles driven "); numOfGallonsLabel.setFont(font); numOfMilesLabel.setFont(font); } private void createInputFields() { numOfGallonsTextField = new TextField(); numOfMilesTextField = new TextField(); } private void addElements(GridPane gridPane) { gridPane.add(numOfGallonsLabel,0,0,2,1); gridPane.add(numOfGallonsTextField,0,1,2,1); gridPane.add(numOfMilesLabel,0,2,2,1); gridPane.add(numOfMilesTextField,0,3,2,1); gridPane.add(calcButton,0,4,1,1); calcButton.setPrefWidth(200); calcButton.setMinWidth(200); calcButton.setAlignment(Pos.CENTER); } private GridPane createRegistrationFormPane() { GridPane gridPane = new GridPane(); gridPane.setAlignment(Pos.CENTER); gridPane.setPadding(new Insets(20)); gridPane.setHgap(20); gridPane.setVgap(5); ColumnConstraints columnOneConstraints = new ColumnConstraints(140,140,Double.MAX_VALUE); columnOneConstraints.setHalignment(HPos.CENTER); ColumnConstraints columnTwoConstrais = new ColumnConstraints(60,60,Double.MAX_VALUE); columnTwoConstrais.setHgrow(Priority.ALWAYS); columnTwoConstrais.setHalignment(HPos.RIGHT); gridPane.getColumnConstraints().add(columnOneConstraints,columnTwoConstrais); return gridPane; } private void calculate() { double MPG; try { int numOfGallons = Integer.parseInt(numOfGallonsTextField.getText()); int numOfMiles = Integer.parseInt(numOfMilesTextField.getText()); MPG = numOfMiles / numOfGallons; if (MPG < 15) { alert(String.format("You got MPG%s",MPG)); } } private void alert(String text) { Alert alert = new Alert(Alert.AlertType.INFORMATION); alert.setTitle("Message"); alert.setHeaderText(null); alert.setContentText(text); alert.getDialogPane().setPrefWidth(300); } } 

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!