Question: This is my javafx code. I can't run it. What is wrong? import com.sun.xml.internal.ws.org.objectweb.asm.ClassAdapter; 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 run it. What is wrong?
import com.sun.xml.internal.ws.org.objectweb.asm.ClassAdapter; 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 jdk.nashorn.internal.scripts.JO;
import javax.swing.*;
public class MilesCalculator extends Application {
private Label numOfGallonsLabel; private Label numOfMilesDrivenLabel;
private TextField numOfGallonsTextField; private TextField numOfMilesDrivenTextField;
private Button calcButton;
public static void main(String[] args) { launch(); }
public void start(Stage primaryStage) throws Exception { primaryStage.setTitle("Miles Per Gallon Calculator for Infite");
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, 250); primaryStage.setScene(scene); }
private void createLabels(Font font) { numOfGallonsLabel = new Label("Total number of gallons: "); numOfMilesDrivenLabel = new Label("Number of miles driven: "); numOfGallonsLabel.setFont(font); numOfMilesDrivenLabel.setFont(font);
}
private void createInputFields() { numOfGallonsTextField = new TextField(); numOfMilesDrivenTextField = new TextField();
}
private void addElements(GridPane gridPane) { gridPane.add(numOfGallonsLabel, 0, 0, 2, 1); gridPane.add(numOfMilesDrivenLabel, 0, 1, 2, 1); gridPane.add(calcButton, 1, 3, 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 columnTwoConstrains = new ColumnConstraints(60, 60, Double.MAX_VALUE); columnTwoConstrains.setHgrow(Priority.ALWAYS); columnTwoConstrains.setHalignment(HPos.RIGHT);
gridPane.getColumnConstraints().addAll(columnOneConstraints, columnTwoConstrains);
return gridPane; }
private void calculate() { double MPG; double numOfGallons; double numOfMilesDriven;
}
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);
alert.showAndWait();
} }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
