title: Handle RadioButton events after button clicked
body: <p>help,
  my questions are:</p>
  
  <ol>
  <li><p>why isn't <code>itemStateChanges</code> triggered, I tried to put it in the inner class <code>ButtonHandler</code> and also in <code>RadioButtonHandler</code> Im having trouble with it, what is the right way to do it? 
  I want to trigger and check the marked JRadioButtons after the user click the "check" button.</p></li>
  <li><p>What is the right way to check which button was clicked, I feel like comparing the strings is bad programming practise. Maybe using an ID ?</p></li>
  <li><p>How should I make a "reset" button(start over), I want to uncheck all radio buttons and run the constructor once again.</p></li>
  </ol>
  
  <p>Thank you for your help !</p>
  
  <pre><code>import java.awt.*;
  import java.awt.event.*;
  import java.util.ArrayList;
  
  import javax.swing.*;
      public class ExamFrame extends JFrame {
  
          static ArrayList&lt;Question&gt; qArrList;
          JRadioButton a1,a2,a3,a4;
          public ExamFrame() {
              super("Quiz");
  
              setLayout(new GridLayout(0, 1));
              GridBagConstraints gbc = new GridBagConstraints();
  
              Exam exam = new Exam();
              qArrList = exam.getExam();
              int count=0;
              for(Question q : qArrList){
                  count++;
                  JLabel questionLabel = new JLabel(count+". "+q.getQustion()); //swing constant ?
                  ArrayList&lt;String&gt; ansRand = q.getAllRandomAns();
                  a1 = new JRadioButton(ansRand.get(0)); 
                  a2 = new JRadioButton(ansRand.get(1));
                  a3 = new JRadioButton(ansRand.get(2));
                  a4 = new JRadioButton(ansRand.get(3));
                  add(questionLabel);
                  add(a1);add(a2,gbc);add(a3);add(a4);
  
                  ButtonGroup radioGroup = new ButtonGroup(); //logical relationship
                  radioGroup.add(a1);radioGroup.add(a2);radioGroup.add(a3);radioGroup.add(a4);
              }
              //buttons:
              JButton checkMe = new JButton("Check Exam");
              JButton refresh = new JButton("Start Over");
              ButtonHandler handler = new ButtonHandler();
              checkMe.addActionListener(handler);
              refresh.addActionListener(handler);
              add(checkMe);
              add(refresh);
  
          }
              /** Listens to the radio buttons. */
              public class ButtonHandler implements ActionListener
              {
                  public void actionPerformed (ActionEvent e) {
                      if(e.getActionCommand().equals("Start Over")){ //id?
                          //how to do this?
  
                      }
                      else{
                          RadioButtonHandler handler = new RadioButtonHandler();
                          a1.addItemListener(handler);
                          System.out.println("success?");
                      }
                      JOptionPane.showMessageDialog(ExamFrame.this, String.format("You pressed: %s", e.getActionCommand()));
                  }
                  public void itemStateChanged(ItemEvent e) //can i add it here?
                  {
                      JOptionPane.showMessageDialog(ExamFrame.this, String.format("yes?"));
                      System.out.println("success!");
                  }
  
              }
              public class RadioButtonHandler implements ItemListener
              {
                  public void itemStateChanged(ItemEvent e)
                  {
                      JOptionPane.showMessageDialog(ExamFrame.this, String.format("radio state changed"));
  
                  }
  
              }
      }
  </code></pre>