Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-21-2008, 03:34 PM
Member
 
Join Date: May 2008
Posts: 9
Judoon_Platoon is on a distinguished road
[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

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);
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); }
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.

If anyone can see whats going on here that would be greatly appreciated.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 05-22-2008, 06:33 AM
Senior Member
 
Join Date: Jul 2007
Posts: 1,222
hardwired is on a distinguished road
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);
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 05-22-2008, 01:54 PM
Member
 
Join Date: May 2008
Posts: 9
Judoon_Platoon is on a distinguished road
I swear I tried doing what you put, hmm must have been something else i was doing wrong. Cheers for that it works perfectly
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to use While loop Java Tip java.lang 0 04-17-2008 09:44 PM
do...while loop eva New To Java 16 01-31-2008 08:44 AM
while loop michcio New To Java 5 01-27-2008 02:56 AM
Referencing JPanel Class uncopywritable New To Java 2 08-12-2007 03:31 PM
A loop that doesn't loop MichYer New To Java 2 07-30-2007 10:44 AM


All times are GMT +3. The time now is 06:59 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org