title: java - catch value of checkbutton in a specific moment
body: <p>I have a dynamic application that need to create a window interface with checkbox. The values of the checkboxes will control the next steps of the program.</p>
  
  <p>So I have that interface with the button and I should select the buttons that I want then press a "RUN" button (in the moment of the choice the program must be waiting).
  How can I do that?</p>
  
  <p>(I cannot use a server application with html tags. It would be too easy.)</p>
  
  <p>This is my code. The problem is that the program controls the values of the checkboxes before I press the RUN button. So all the button states result in FALSE.</p>
  
  <pre><code>public class JRadiobuttonExample extends JFrame {
  private JCheckBox radioButton1;
  private JCheckBox radioButton2;
  private JCheckBox radioButton3;
  private JLabel label;
  int i, state[] =  {0,0,0,0};
  JCheckBox b[]; 
  static ArrayList&lt;Boolean&gt; check=new ArrayList&lt;Boolean&gt;();
  JButton altervista=new JButton("RUN");
  static int num;
  
  
  public JCheckBox[] getB() {
      return b;
  }
  public void setB(JCheckBox[] b) {
      this.b = b;
  }
  public ArrayList&lt;Boolean&gt; getCheck() {
      return check;
  }
  public void setCheck(ArrayList&lt;Boolean&gt; check2) {
      check = check2;
  }
  public JRadiobuttonExample(int num, ArrayList&lt;String&gt; lbl) {
      super("JRadiobuttonExample");
      getContentPane().setLayout(new FlowLayout(FlowLayout.CENTER));
  
      b= new JCheckBox[num];
  
      CheckBoxListener ckListener = new CheckBoxListener();
  
      for(i=0; i&lt;num; i++) {
          b[i] = new JCheckBox(lbl.get(i));
          b[i].addItemListener(ckListener); 
          getContentPane().add(b[i]);
      }
  
      setVisible(true); 
  
      getContentPane().add(altervista);
      getContentPane().setVisible(true);
      Ascoltatore asc=new Ascoltatore();
      altervista.addActionListener(asc);
  }
  
  class Ascoltatore extends WindowAdapter implements ActionListener{
      public void windowClosing(WindowEvent e){
  
      }
      public void actionPerformed(ActionEvent e){
          if(e.getSource()==altervista){
  
          }
      }
  }
  
  
  
  public static void main(String argv[])
  {
      ArrayList&lt;String&gt; col=new ArrayList&lt;String&gt;();
  
      col.add("hello");
      col.add("everyone");
  
      num=col.size();
      JRadiobuttonExample b = new JRadiobuttonExample(num,col);
      JCheckBox[] buttons=b.getB();
  
      for (JCheckBox c:buttons){
          check.add(c.isSelected());
      }
  
      System.out.println("checkbox values are:");
      for (boolean sel:check ){
          System.out.println(sel);
      }
  }
  }
  </code></pre>