Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This is javafx code. It is run but I want to add message. when i don't put nothing. And when i click calculate button without

This is javafx code. It is run but I want to add message. when i don't put nothing. And when i click calculate button without put in number, it's not working. package Homework; import javafx.application.Application; import javafx.geometry.Pos; import javafx.scene.Scene; import javafx.scene.control.*; import javafx.scene.control.Button; import javafx.scene.control.Label; import javafx.scene.control.TextField; import javafx.scene.layout.*; import javafx.scene.text.Font; import javafx.scene.text.FontWeight; import javafx.stage.Stage; import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.geometry.Insets; import javafx.scene.control.RadioButton; import javafx.stage.Stage; import javafx.scene.layout.GridPane; import java.awt.Checkbox; import javafx.scene.control.CheckBox; import org.w3c.dom.events.Event; import javafx.application.Platform; import java.text.DecimalFormat; public class Reimbursement extends Application implements EventHandler { //Array with coffee name  private String[] coffeeNames = {"Regular", "Espresso", "Latte", "Frappucino", "Mocha"}; Stage window; Scene scene; Button btn; Button resetButton; TextField textDays; TextField textAirFare; TextField textCarRental; TextField textMilesDriven; TextField textParkingFees; TextField textTaxiCharges; TextField textRegisFees; TextField textLodgingCharges; TextField textSelection; ComboBox comboBox; CheckBox correctCheckBox; RadioButton button1; @Override public void start(Stage primaryStage) throws Exception { window = primaryStage; window.setTitle("Reimbursement Calculator"); Font font = Font.font("Arial", FontWeight.BOLD, 12); //GridPane with 10 px padding around edge  GridPane grid = new GridPane(); grid.setAlignment(Pos.CENTER); grid.setPadding(new Insets(20)); grid.setHgap(20); grid.setVgap(5); //Label1  Label lbl1 = new Label("Number of days on the trip: "); GridPane.setConstraints(lbl1, 0, 0); GridPane.setRowIndex(lbl1, 0); lbl1.setFont(font); //Label 2  Label lbl2 = new Label("Amount of airfare: "); GridPane.setConstraints(lbl2, 0, 0); GridPane.setRowIndex(lbl2, 2); lbl2.setFont(font); //Label 3  Label lbl3 = new Label("Amount of car rental fees: "); GridPane.setConstraints(lbl3, 0, 0); GridPane.setRowIndex(lbl3, 4); lbl3.setFont(font); //Label 4  Label lbl4 = new Label("Number of miles driven:"); GridPane.setConstraints(lbl4, 0, 0); GridPane.setRowIndex(lbl4, 7); lbl4.setFont(font); //Label 5  Label lbl5 = new Label("Amount of parking fees:"); GridPane.setConstraints(lbl5, 0, 0); GridPane.setRowIndex(lbl5, 9); lbl5.setFont(font); //Label 6  Label lbl6 = new Label("Amount of taxi charges:"); GridPane.setConstraints(lbl6, 0, 0); GridPane.setRowIndex(lbl6, 11); lbl6.setFont(font); //label 7  Label lbl7 = new Label("Conference registration:"); GridPane.setConstraints(lbl7, 0, 0); GridPane.setRowIndex(lbl7, 13); lbl7.setFont(font); //label 8  Label lbl8 = new Label("Lodging charges:"); GridPane.setConstraints(lbl8, 0, 0); GridPane.setRowIndex(lbl8, 15); lbl8.setFont(font); //selection label  Label lbl10 = new Label("Selection:"); GridPane.setConstraints(lbl10,0,0); GridPane.setRowIndex(lbl10,20); lbl10.setFont(font); //info correct label  Label lbl11= new Label("This information is correct:"); GridPane.setConstraints(lbl11,0,0); GridPane.setRowIndex(lbl11,22); lbl11.setFont(font); //create personal radio button  RadioButton button1 = new RadioButton("Personal Vehicle used?"); button1.setFont(font); button1.setOnAction(e -> { textMilesDriven.setDisable(!button1.isSelected()); if (!button1.isSelected()) { textMilesDriven.setText(""); } }); GridPane.setConstraints(button1, 0, 0); GridPane.setRowIndex(button1, 6); //Textfield1  textDays = new TextField(""); textDays.setPrefWidth(110); GridPane.setConstraints(textDays, 0, 0); GridPane.setRowIndex(textDays, 1); //textfield 2  textAirFare = new TextField(""); textAirFare.setPrefWidth(110); GridPane.setConstraints(textAirFare, 0, 0); GridPane.setRowIndex(textAirFare, 3); //textfield 3  textCarRental = new TextField(""); textCarRental.setPrefWidth(110); GridPane.setConstraints(textCarRental, 0, 0); GridPane.setRowIndex(textCarRental, 5); //textfield 4  textMilesDriven = new TextField(""); textMilesDriven.setPrefWidth(110); //Disable textfield unless user choose radiobutton  textMilesDriven.setDisable(!button1.isSelected()); GridPane.setConstraints(textMilesDriven, 0, 0); GridPane.setRowIndex(textMilesDriven, 8); //textfield 5  textParkingFees = new TextField(""); textParkingFees.setPrefWidth(110); GridPane.setConstraints(textParkingFees, 0, 0); GridPane.setRowIndex(textParkingFees, 10); //textfield 6  textTaxiCharges = new TextField(""); textTaxiCharges.setPrefWidth(110); GridPane.setConstraints(textTaxiCharges, 0, 0); GridPane.setRowIndex(textTaxiCharges, 12); //textfield 7  textRegisFees = new TextField(""); textRegisFees.setPrefWidth(110); GridPane.setConstraints(textRegisFees, 0, 0); GridPane.setRowIndex(textRegisFees, 14); //textfield 8  textLodgingCharges = new TextField(""); textLodgingCharges.setPrefWidth(110); GridPane.setConstraints(textLodgingCharges, 0, 0); GridPane.setRowIndex(textLodgingCharges, 16); //selection textfield  textSelection = new TextField(""); textSelection.setPrefWidth(110); GridPane.setConstraints(textSelection,0,0); GridPane.setRowIndex(textSelection,20); GridPane.setColumnIndex(textSelection,1); textSelection.setText("Regular"); textSelection.setEditable(false); textSelection.setFont(font); //Assign all values for combo box  comboBox = new ComboBox<>(); comboBox.getItems().addAll("Regular", "Espresso", "Latte", "Frappucino", "Mocha"); comboBox.setOnAction(e -> textSelection.setText(comboBox.getValue())); comboBox.setValue("Regular"); //correct checkbox  correctCheckBox = new CheckBox(); grid.add(correctCheckBox,1,22); VBox layout = new VBox(10); Label lbl9 = new Label("Select Favorite Coffee:"); lbl9.setFont(font); GridPane.setConstraints(lbl9, 0, 0); GridPane.setRowIndex(lbl9, 18); GridPane.setColumnIndex(lbl9,0); layout.setPadding(new Insets(20, 20, 20, 20)); layout.getChildren().addAll(comboBox); scene = new Scene(layout, 400, 600); GridPane.setConstraints(layout, 0, 0); GridPane.setRowIndex(layout, 19); GridPane.setColumnIndex(comboBox,1); //Reset Button  resetButton = new Button("Reset"); resetButton.setFont(font); resetButton.setOnAction(e -> reset()); GridPane.setConstraints(resetButton,0,0); GridPane.setRowIndex(resetButton,25); GridPane.setColumnIndex(resetButton,0); //Calculate Button  btn = new Button("Calculate Reimbursement"); btn.setFont(font); GridPane.setConstraints(btn, 0, 0); GridPane.setRowIndex(btn, 25); GridPane.setColumnIndex(btn,1); grid.getChildren().addAll(lbl1, lbl2, lbl3, lbl4, lbl5, lbl6, lbl7, lbl8, lbl9,lbl10,lbl11, textDays, textAirFare, textCarRental, textMilesDriven, textParkingFees, textTaxiCharges, textRegisFees, textLodgingCharges,textSelection, btn, button1, layout,resetButton); btn.setOnAction(this); /**  * start the scene  */  Scene scene = new Scene(grid, 300, 600); primaryStage.setTitle("Reimbursement"); primaryStage.setScene(scene); primaryStage.show(); } private void reset(){ textCarRental.setText(""); textDays.setText(""); textMilesDriven.setText(""); textLodgingCharges.setText(""); textRegisFees.setText(""); textTaxiCharges.setText(""); textParkingFees.setText(""); comboBox.setValue(comboBox.getItems().get(0)); textSelection.setText(comboBox.getItems().get(0)); } @Override public void handle(ActionEvent event) { double days, airfare, carRental, miles, milesdriven, parking, taxi, conference, lodging, travelExpenses, paidAmount; double allowableExpenses = 506.25; double meals = 37.00; double parkingFees = 10.00; double taxiCharges = 20.00; double lodgingCharges = 95.00; double carRent = 0.27; //decimal format  DecimalFormat dollar = new DecimalFormat("$#,##0.00"); days = Integer.parseInt(textDays.getText()); airfare = Double.parseDouble(textAirFare.getText()); carRental = Double.parseDouble(textCarRental.getText()); miles = Double.parseDouble(textMilesDriven.getText()); parking = Double.parseDouble(textParkingFees.getText()); taxi = Double.parseDouble(textTaxiCharges.getText()); conference = Double.parseDouble(textRegisFees.getText()); lodging = Double.parseDouble(textLodgingCharges.getText()); milesdriven = miles * carRent; travelExpenses = days * lodging + carRental + airfare + parking + taxi + conference; paidAmount = travelExpenses - allowableExpenses; if (paidAmount < 0) { paidAmount = 0; } Alert alert = new Alert(Alert.AlertType.INFORMATION); if (event.getSource() == btn) { alert.setTitle("Message"); alert.setHeaderText(""); alert.setContentText(String.format("Total Expenses: $%s " + "Allowable Expenses: $%s Amount to be paid: $%s", travelExpenses, allowableExpenses, paidAmount)); alert.showAndWait(); } } public static void main(String[] args) { launch(args); } } 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Support For Data Mining Applications Discovering Knowledge With Inductive Queries Lnai 2682

Authors: Rosa Meo ,Pier L. Lanzi ,Mika Klemettinen

2004th Edition

3540224793, 978-3540224792

More Books

Students also viewed these Databases questions

Question

What is the role of an advertising agency?

Answered: 1 week ago

Question

5. Identify three characteristics of the dialectical approach.

Answered: 1 week ago