title: Enabling a Button by checking all the required checkbox
body: <p>I'm trying to create a program where a <code>JButton</code> will only be enabled if all the <code>JCheckBoxes</code> are Checked, But I'm having problem with enabling the specific <code>JButton</code> because once I checked all the <code>JCheckBoxes</code> the only <code>JButton</code> being enabled is the last created </p>
  
  <p>Here's my code:</p>
  
  <pre><code>public class Practice extends JFrame implements ActionListener
  {
      JPanel main=new JPanel();
      JPanel gui=new JPanel();
      JButton btnadd=new JButton("Add Timer");
      JPanel order=new JPanel();
      JPanel chkPanel=new JPanel();
      JButton remove=new JButton("Remove");
  
      public Practice()
      {
  
          main.setLayout(new BorderLayout());
          gui.setLayout(new FlowLayout());
          main.add(btnadd, BorderLayout.NORTH);
          main.add(gui,BorderLayout.CENTER);
          add(main);
          btnadd.addActionListener(new ActionListener() 
          {
              int ctr=0;
              @Override
              public void actionPerformed(ActionEvent e) 
              {
                  ctr+=1;
                  //addPanel();
                  //System.out.print(x);
                  addPanel(ctr);
                  revalidate();
                  repaint();
              }
          });
  
          main.add(gui);
      }
  
  
      public void addPanel(int ctr)
      {
          Border blackline=BorderFactory.createLineBorder(Color.BLACK);
          order=new JPanel();
          order.setPreferredSize(new Dimension(200,300));
          order.setLayout(new BorderLayout());
          TitledBorder title=BorderFactory.createTitledBorder(blackline);
          title.setTitleJustification(TitledBorder.LEFT);
          order.setBorder(title);
          addCheckPanel(ctr);
          addBtn();
          gui.add(order);
      }
  
      public void addCheckPanel(int ctr)
      {
          chkPanel=new JPanel();
          chkPanel.setLayout(new BoxLayout(chkPanel, BoxLayout.Y_AXIS));
          for(int i=0;i&lt;ctr;i++)
              addCheck(ctr);
          order.add(chkPanel);
      }
      int y;
      public void addCheck(int ctr)
      {
          JCheckBox check=new JCheckBox("Check Me");
          chkPanel.add(check);
          y=ctr;
          check.addActionListener(listener);
  
      public void addBtn()
      {
          remove=new JButton("Remove");
          order.add(remove, BorderLayout.SOUTH);
          remove.setEnabled(false);
          remove.addActionListener(listener);
      }
  
      public static void main(String args[])
      {
          TimerPractice p=new TimerPractice();
          p.setSize(1000,800);
          p.setVisible(true);
          p.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          p.setLocationRelativeTo(null);
      }
  
      ActionListener listener=new ActionListener()
      {
          @Override
          public void actionPerformed(ActionEvent e)
          {
               Object source = e.getSource();
               if (source instanceof Component) 
               {
                  Component comp = (Component)source;
                  gui.remove(comp.getParent());
                  revalidate();
                  repaint();
               }
           }
      };
  
  
      @Override
      public void actionPerformed(ActionEvent e) 
      {
  
      }
  }
  </code></pre>