title: How can I get an Object's name in java
body: <p>I have a group of radio buttons that doesn't includes any text on frame 1.</p>
  
  <p>Every button has a <code>j</code> label <code>l</code>, which means that when I choose one radio button, I want to change the icon of a specific <code>j</code> label.</p>
  
  <p>I want to know which button is selected to send it to frame 2 by a constructor.</p>
  
  <p>So I want send the variable of the current radio button that's clicked.</p>
  
  <p>How can i do that?</p>
  
  <pre><code>public String getSelectedButtonText(ButtonGroup buttonGroup) {
      for (
          Enumeration&lt;AbstractButton&gt; buttons = buttonGroup.getElements();
          buttons.hasMoreElements();
      ) {
          AbstractButton button = buttons.nextElement();
  
          if (button.isSelected()) {
              return button.getText();
          }
      }
  
      return null;
  }
  </code></pre>