My code is giving me trouble with running FXML. when i click the radio button metric nothing gets printed out when i click the button. i am using scene builder to do this. code is in java.   here is the code BMI BUTTON CODE import javafx.beans.value.ChangeListener; import javafx.beans.value.ObservableValue; import javafx.event.ActionEvent; import javafx.fxml.FXML; import javafx.scene.control.Label; import javafx.scene.control.TextField; import javafx.scene.control.Button; import javafx.scene.control.RadioButton; import java.text.DecimalFormat;

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

My code is giving me trouble with running FXML. when i click the radio button metric nothing gets printed out when i click the button. i am using scene builder to do this. code is in java.

 

here is the code

BMI BUTTON CODE

import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.control.Button;
import javafx.scene.control.RadioButton;
import java.text.DecimalFormat;


public class BMICalculateButton
{
     
    @FXML
    private Button BMIButton;

    @FXML
    private TextField weightTextField;

    @FXML
    private TextField heightTextField;

    @FXML
    private TextField BMICalculationTextField;
    
    @FXML
    private RadioButton EnglishRadioButton;
    
    @FXML
    private RadioButton MetricRadioButton;
    
    

    @FXML
    void handleButtonAction(ActionEvent event) {
      try {
      // To do task: get the input and add to result label
      String input1 = weightTextField.getText();
      String input2 = heightTextField.getText();
      DecimalFormat format = new DecimalFormat(".00");
      double weight = Integer.parseInt(input1);
      double height = Integer.parseInt(input2);
      
      double BMI;
      
      if(EnglishRadioButton.isSelected())
      {
      BMI = (weight * 703 )/ (height * height);
      
      
      

      }
      else if(MetricRadioButton.isSelected())
      {
      BMI = (weight)/ (height * height);
        
        BMICalculationTextField.setText(String.valueOf(format.format(BMI)));
        
        
      }
      else
      {
      BMICalculationTextField.setText(String.valueOf(format.format(BMI)));
      }
      
        }
      catch (NumberFormatException ex) {
         weightTextField.setText("");
         heightTextField.setText("");
      }    
   }

   // called by FXMLLoader to initialize the controller
   public void initialize() {
      // listener for changes to number1TextField's text
      weightTextField.textProperty().addListener(
         new ChangeListener<String>() {
            @Override
            public void changed(ObservableValue<? extends String> ov, 
               String oldValue, String newValue) {
               BMICalculationTextField.setText("");
            }
         }
      );

      // listener for changes to number2TextField's text
      heightTextField.textProperty().addListener(
         new ChangeListener<String>() {
            @Override
            public void changed(ObservableValue<? extends String> ov, 
               String oldValue, String newValue) {
               BMICalculationTextField.setText("");
            }
         }
      );
   }
}

 

LAUNCHER CODE

 

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;

public class BMICalculator extends Application {
   @Override
   public void start(Stage stage) throws Exception {
      Parent root = 
         FXMLLoader.load(getClass().getResource("BMICalculator.fxml"));

      Scene scene = new Scene(root); // attach scene graph to scene
      stage.setTitle("BMICalculateButton"); // displayed in window's title bar
      stage.setScene(scene); // attach scene to stage
      stage.show(); // display the stage
   }

   public static void main(String[] args) {
      // create a Addition object and call its start method
      launch(args); 
   }
}

Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Running Time of Application
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education