This week's giveaway is in the EJB and other Java EE Technologies forum. We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line! See this thread for details.
I create a GUI with 10 check boxes but these check boxes are from an array and all have the same name.e.g.
I tick box 4 and i want it to tell me which box i have ticked...how do i get that reference so can get the label to read out "You have ticked box 4"?
I can get it's reference in the sense that it says test, but they all say test, so which test box did you tick?
The obvious solution is to make the for loop give them all a different name.e.g.test1, test2 etc but they all have to have the same name because in the real instance of what i am doing i have a tabbed pane and on clicking "New Tab" it creates a replica of the existing tab so checkbox in in tab 1, checkbox is in tab 2 etc and when i tick a box i need to makes it's actions relevant only to that tab.
Using one Listener: nice non‑object‑oriented programming. Create a Listener for each button; you would probably have to write a NumberListener or similar. Add it to the button (one instance each) in the loop. You can use the same String to number the buttons, label them, and to use in the NumberListenerₑs methods.