October 25th, 2012, 06:47 AM
Join Date: Oct 2012
Time spent in forums: 57 m 27 sec
Reputation Power: 0
[Assignment/Homework] Problem with concatenation/Text Fields
Hello, I'm new and just need this problem fixed, and have no idea how to do it.
I have several text fields and am trying to put an integer (from a two-dimensional array) into them.
The name of the text fields have "jtf" and then two numbers corresponding to what the numbers are in the 2D array.
I am trying to do this using a for loop, here is an example of what I have:
p1.add(jtf00 = new JTextField(""));
p1.add(jtf01 = new JTextField(""));
p1.add(jtf02 = new JTextField(""));
p1.add(jtf03 = new JTextField(""));
p1.add(jtf10 = new JTextField(""));
p1.add(jtf11 = new JTextField(""));
for (int i = 0; i < gameGrid.buttonarray.length; i++)
for (int j = 0; j < gameGrid.buttonarray.length; j++)
String temp = "jtf" + i + "" + j;
I'm not sure what to put in <___> and I'm not even sure if there is such code for it. I am trying to concatenate the "jtf" with "i" and "j" which will change the value in the 2D array as well, however a text field name needs to go in the <___> area and as you can see I tried to make a new String with the text field name, but temp.setText(Integer.toString(gameGrid.buttonarray[i][j])); doesn't work because it is trying to get something from the String class.
Any help would be appreciated!
Last edited by javagos : October 25th, 2012 at 08:05 AM.
Reason: Wrong Title