Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Java text fields to 2D array  RSS feed

 
terrence mann
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm having an issue populating a 2D array from textfields. The GUI has 2 buttons and 2 textfields. Everytime the enter button is pushed it should store the values in the 2 text fields into the array. When the report button is pushed it should output all the values in the array to a textarea. The end result should be a 2D array with 2 columns and unlimited rows that stores the values until the report button is pushed. Any help would be greatly appreciated.

 
Paul Clapham
Sheriff
Posts: 22185
38
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
terrence mann wrote:I'm having an issue populating a 2D array from textfields.

And what exactly is that issue?

By the way, if you enclose your code in the "Code" tags (see that "Code" button above the box where you post?) then your code will show up nicely and people will be more likely to read it. I have to admit that I didn't read your code, but then you didn't ask a question about it.
 
terrence mann
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul I appreciate the quick response and apologize for the horrible code post. The issue that I am having with this code is that whenever I click the enter button it doesn't add the value to the array and add a new row. it just writes the value in [0][0] and [0][1] again. I need it to write the value in the text boxes to the array. Then the next time the enter button is clicked add the values in the text boxes to the next row in the array. Thanks again for your quick response.
 
Paul Clapham
Sheriff
Posts: 22185
38
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Add a new row? To that double [][] tutorArray? It isn't possible to add rows to an array. You could make a new array with one more row, and copy over the existing data from the old array to the new array, but I would advise using some data structure which is less unsuitable.

And you seem to have the Swing aspects working okay, right? You click on the button and it updates the array? Then this isn't really a Swing question. Unless it's a question about how to display that array in Swing... right now you're just trying to update it, but later you might want to display it somehow. And if that was a requirement, it would lead to an answer about the suitable data structure.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!