title: Display message dialog if JTextField does not contain data
body: <p>I am writing a BMI calculator application. Currently an error happens which causes the program to stop working if I do not enter data into one field. For instance, there are two JTextFIelds for 'height', one being feet and the other inches. If I just input '6' into the feet JTextField and enter nothing into inches JTextField, then enter my weight in the weight JTextField and click on calculate, it does not work.</p>
  <p>What I want to do is display a message dialog saying &quot;Please make sure all fields are filled in&quot; if one field does not contain data.</p>
  <p>Below is the ActionHandler code that is added to my 'Calculate' button.</p>
  <pre><code>public void actionPerformed(ActionEvent e) {
      double heightFT = ((Double.parseDouble(heightFt_TF.getText()));
      double heightIn = (Double.parseDouble(heightIn_TF.getText()));
      double weight = (Double.parseDouble(weight_TF.getText()));
      double totalHeight = (heightFT*12) + heightIn;              
              
      BMI = (weight / (totalHeight*totalHeight)) * 703;
      String s = BMI+&quot;&quot;;
      s = s.substring(0,4);
      BMI_TF.setText(s);                              
  }
  </code></pre>
  <hr />
  <h3>Solved</h3>
  <p>I have now fixed the problem. What I did was add 'throws NumberFormatException' in the method and did a try catch. In the try code block I wrote the code I want to execute if all data fields are entered. In the catch clause I wrote code that uses the NumberFormatException and simply displays the message dialog with the error message. Now, if one field is not entered, the message dialog appears!</p>