-1

Possible Duplicate:
Dynamic variable names Java

I'm creating a Sudoku solver / generator in Java. I'm using NetBeans as the IDE. I created an applet and designed it in the NetBeans GUI designer. For the fields (that hold numbers in a 9*9 matrix) i used text fields and i named the variables according to their position in the matrix. For instance, the first one is num_1_1. The first number represents the row and the second one represents the column.

The actual generator / solver will work with a 2 dimensional integer array (int[][]) and when it generates / solves a sudoku it will populate the text vields in the gui with the numbers from the array.

Now, is there a way where i can use say a for loop to loop trough the veriable names and assign each one that way? Something like:

for(int x = 0; x < 9; x++){
    for(int y = 0; y < 9; y++){
        num+"_"+x+"_"+y = 5;
    }
}

Thanks!

Community
  • 1
  • 1
Squeazer
  • 1,234
  • 1
  • 14
  • 33
  • 1
    As well as http://stackoverflow.com/questions/6729605/dynamic-variable-names-in-java and http://stackoverflow.com/questions/1192534/is-there-away-to-generate-variables-names-dynamically-in-java and http://stackoverflow.com/questions/5885669/dynamic-java-variable-naming – skaffman Feb 12 '12 at 00:42
  • As a solution to your problem: use a JTable! – fortran Feb 12 '12 at 00:48

1 Answers1

2

No, there isn't, at least not in a way that isn't total overkill for what you want. Don't use explicit vars, use an array of arrays of text fields. There is a reflection API, but that is not called for here.

colbadhombre
  • 803
  • 8
  • 11