Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 183
  • Last Modified:

keep track of the order they were checked?

Hello everyone!

Using the code below, if I had 50 different checkboxs in 7 different JPanels with 7 different name groups (example kp1-kp10  kk1-kk10  bl1-bl8 etc how would I be able to have each checkbox as it was checked go into an arraylist to keep track of the order they were checked?



public class CheckBoxesToAudioFiles {
Map checkToAudio;

public CheckBoxesToAudioFiles {
checkToAudio = new HashMap();
}

public void mapCheckboxToAudioFile(JCheckbox cb, AudioFile af) {
checkToAudio.put(cb, af);
}

public AudioFile getAudioFileForCheckbox(JCheckbox cb) {
(AudioFile)return checkToAudio.get(cb);
}

}

0
Drop_of_Rain
Asked:
Drop_of_Rain
  • 2
1 Solution
 
objectsCommented:
you would use an ActionListener:

cb.addActionListener(new ActionListener()
{
   public void actionPerformed(ActionEvent event)
   {
      JCheckBox cb = (JCheckBox) event.getSource();
      if (cb.isSelected())
      {
         choices.add(cb);
      }
   }
});
0
 
Drop_of_RainAuthor Commented:
I can see it now, very easily I'm starting to get the hand on reading this code, this is starting to get really fun. I don't know what I would do wiyhout your help and others.  I will have a lot more questions, you will earn a lot of points from me and so will others.

Thanks again,
Christopher
0
 
objectsCommented:
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now