title: How to get value of selected radioButton of buttonGroup
body: <p>How to get value of selected <code>radioButton</code>?
  I tried using <code>buttonGroup1.getSelection().getActionCommand()</code> (as posted in some of answers here) but it is not working.
  Also, i am temporarily using this code but i want to know is this a good practice or not?</p>
  
  <pre><code>//Consider that maleRButton and femaleRButton are two radioButtons of 
  //same buttonGroup
  String getGender()
  {
      if(maleRButton.isSelected())
      {
          return "Male";
      }
      else if(femaleRButton.isSelected())
      {
          return "Female";
      }
      else
      {
          return null;
      }
  }
  </code></pre>