Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

textbox loop naming

 
jason gass
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can you do a loop like this:

for (int i = 1; i<=10; i++)
textPanel.add (new JTextField(i + "") );

and name them in order, like text1,text2, text3?

So you can then refer to them like:

text1.addActionListener( textHandler );
 
Elouise Kivineva
Ranch Hand
Posts: 154
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you create the references inside the loop you will not have them outside the loop.

You could create the references earlier and instantiate them (use the "new" keyword) inside a loop.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can access the JTextFields, without naming them

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic