Results 1 to 3 of 3
- 05-21-2008, 01:34 PM #1
Member
- Join Date
- May 2008
- Posts
- 9
- Rep Power
- 0
[SOLVED] Referencing Variable within Loop
I am near to completing my application which has been somewhat challenging, it is due friday. I have all of my Labels etc nicely within Frames. my only problem is that only 1 of my Checkboxes are displaying instead of the 8 that should.
For what it's worth this is the parralel array and Checkbox init code
Java Code://parralel Array final String TURBINE_NAME [] = {"Judoon 3X", "Gallifrey 3000", "Veridian AX25", "Kasterborous M4", "Axxon 300","Dradis CF9", "Kenobi 0B1", "J-Dorian"}; CheckboxGroup Wind_Turbine_CheckboxGroup = new CheckboxGroup (); Checkbox Wind_Turbine_Checkbox [] = new Checkbox [TURBINE_NAME.length]; Checkbox Hidden_Checkbox = new Checkbox ("", true, Wind_Turbine_CheckboxGroup);This does everything I need except it only displays one of the Checkboxes. I tried referencing the Wind_Turbine_Checkbox outside the loop, but it just errors and says it cannot find the variable. I am seriously out of ideas.Java Code:for (int i = 0; i < TURBINE_NAME.length; i++) { Wind_Turbine_Checkbox [i] = new Checkbox (TURBINE_NAME [i], false, Wind_Turbine_CheckboxGroup); Wind_Turbine_Checkbox [i].addItemListener(this); Panel CheckboxPanel = new Panel (new GridLayout (4, 2, 1, 1)); CheckboxPanel.add (Wind_Turbine_Checkbox [i]); Panel ApplicationPanel = new Panel (new GridLayout (4, 1, 10, 1)); ApplicationPanel.add (TurbineLayoutPanel); ApplicationPanel.add (CheckboxPanel); ApplicationPanel.add (choice_panel); ApplicationPanel.add (DisplayPanel); add (ApplicationPanel); }
If anyone can see whats going on here that would be greatly appreciated.
- 05-22-2008, 04:33 AM #2
Java Code:Panel CheckboxPanel = new Panel (new GridLayout (4, 2, 1, 1)); for (int i = 0; i < TURBINE_NAME.length; i++) { Wind_Turbine_Checkbox [i] = new Checkbox (TURBINE_NAME [i], false, Wind_Turbine_CheckboxGroup); Wind_Turbine_Checkbox [i].addItemListener(this); // Making a new panel each time will only have the last checkBox in it. //Panel CheckboxPanel = new Panel (new GridLayout (4, 2, 1, 1)); CheckboxPanel.add (Wind_Turbine_Checkbox [i]); } Panel ApplicationPanel = new Panel (new GridLayout (4, 1, 10, 1)); ... ApplicationPanel.add (CheckboxPanel); ... add (ApplicationPanel);
- 05-22-2008, 11:54 AM #3
Member
- Join Date
- May 2008
- Posts
- 9
- Rep Power
- 0
Similar Threads
-
How to use While loop
By Java Tip in forum java.langReplies: 0Last Post: 04-17-2008, 07:44 PM -
do...while loop
By eva in forum New To JavaReplies: 16Last Post: 01-31-2008, 06:44 AM -
while loop
By michcio in forum New To JavaReplies: 5Last Post: 01-27-2008, 12:56 AM -
Referencing JPanel Class
By uncopywritable in forum New To JavaReplies: 2Last Post: 08-12-2007, 01:31 PM -
A loop that doesn't loop
By MichYer in forum New To JavaReplies: 2Last Post: 07-30-2007, 08:44 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks