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

dynamically added jtextfield values  RSS feed

 
Tai Yo
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
jPanel consists 5 jTextFields. I am adding dynamically jPanels by addButton. And retrieving dynamically added jPanel values by saveButton. The code of saveButton:

I have entered 1, 2, 4, 5, 3 to jTextFields and when I click saveButton, output I got jTextField values as: 1, 2, 3, 4, 5.
Even if I write count==4 after count==2, anyway output I am getting in ordered line.
I would like to ask how can I get the value of count==4 after count==2?
 
Campbell Ritchie
Sheriff
Posts: 53750
127
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My, that is not good code. All those casts are a “code smell”.
And what does that code do? It is quite illegible.
 
Tai Yo
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
could you suggest me best way to get dynamic values?
 
Tai Yo
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Campbell Ritchie I think you was right about code quality.
I have changed it. I have created getter fields for each jTextField and retrieved their values from saveButton.
Thank you. I have solved my problem.
 
Campbell Ritchie
Sheriff
Posts: 53750
127
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please start by explaining what you are trying to do. You are looping through an array and then doing a lot of if tests, which don't appear to do anything different.
Find out what equals(null) returns.
 
Tai Yo
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I totally changed the code, now I don't use above code because of much confusing. I found that with getter method possible to solve it in easy way.
Moderator: possible to delete this post?
 
Campbell Ritchie
Sheriff
Posts: 53750
127
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well done simplifying it Please show us what you have achieved.

We only delete posts if there is something wrong with them, because other people might learn from this post.
 
Tai Yo
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have changed code based on following example:
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!