0

I was wondering if there was a way to check the number of checkboxes checked in Java. I found plenty of instruction on how to do in in javascript but not Java. Thanks for you help!

mKorbel
  • 109,525
  • 20
  • 134
  • 319
Rostro
  • 148
  • 2
  • 3
  • 15
  • @RJ I saw that one but it really didn't didn't give me an adequate answer. It assumes a higher level of knowledge of the language than I have. Perhaps someone could post a better answer on that question? – Rostro Apr 08 '13 at 03:38
  • Then answer from the above link is about as basic as it gets. Using an ArrayList is one of the most commonly used classes in Java. Create a SSCCE to learn the basic concepts. If you have trouble then you post the SSCCE. That is create a loop that create the check boxes and adds them to the GUI and the ArrayList. Then add a button to the GUI that iterates through the ArrayList and displays the number of selected checkboxes. – camickr Apr 08 '13 at 06:05

1 Answers1

1

A few options that I can think of-

  1. Every time a checkbox is checked, increment a (global) counter in its listener. Decrement the counter when the checkbox is un-checked. So, at any given point in time, you know the number of checkboxes checked

  2. Iterate through all the checkboxes and check how many of them are checked. It would be good if you create a collection of checkboxes that you would be using in your code

  3. If the checkboxes are on different screens or in different classes, then you need to main counter at all places and sum them up whenever you want to know the number of checkboxes checked in your application

Sudhanshu Umalkar
  • 4,174
  • 1
  • 23
  • 33
  • I'm sorry but this is a little beyond me. Can you give some examples of how this actually works or some resource I can look at? Thanks! – Rostro Apr 08 '13 at 20:10