Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / August 2007

Tip: Looking for answers? Try searching our database.

Dynamic variables

Thread view: 
McGowan - 01 Aug 2007 16:39 GMT
Hi, I am trying to loop through 81 text boxes each time reading the
text from the box and placing it in a 2d array.

My code below shows it doing just the first line so only 9 text boxes

   private void jButton1_actionPerformed(ActionEvent e) {
       int userAnswer [][] = new int [9][9];

       for (int i = 0; i < 9; i++)  {
           try {
               userAnswer [0][i] = Integer.valueOf(A1.getText());
           } catch (NumberFormatException nf) {
               userAnswer[0][i] = 0;
           }
       System.out.println(i + " " + userAnswer[0][i]);
       }
   }

Where it says A1 I want it to change automatically to A2, A3, A4 and
so on on each iteration of the loop increasing by 1 all the way to 9.

Any ideas?

Thanks,
OIiver
Hendrik Maryns - 01 Aug 2007 17:39 GMT
McGowan schreef:
> Hi, I am trying to loop through 81 text boxes each time reading the
> text from the box and placing it in a 2d array.
[quoted text clipped - 18 lines]
>
> Any ideas?

Put your A* in an array of their own (A would offer itself as a name,
were it not that by convention, names of variables start with a lower
case letters, and such short names are very cryptic), and use the array
index.

H.
Signature

Hendrik Maryns
http://tcl.sfs.uni-tuebingen.de/~hendrik/
==================
http://aouw.org
Ask smart questions, get good answers:
http://www.catb.org/~esr/faqs/smart-questions.html

Daniel Pitts - 01 Aug 2007 19:29 GMT
> Hi, I am trying to loop through 81 text boxes each time reading the
> text from the box and placing it in a 2d array.
[quoted text clipped - 21 lines]
> Thanks,
> OIiver

Is this by any chance a Sudoku related project :-)

Like Hendrik suggests, you should use an array of textAreas, rather
than 81 seperate instances. That way you can create them and add them
to your panel in a loop as well.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.