Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

java.lang.reflect.Field

Status
Not open for further replies.

jackz15

Programmer
Jun 28, 2006
103
US
In my program, I want have Java create multiple distinct buttons that i can individually reference to. A tedious way for the same effect would be:
JButton button = new JButton(words);
JButton button1 = new JButton(words);
JButton button2 = new JButton(words);
//sets different sizes for different buttons
button1.setSize(56,654);
button2.setSize(45,23);
But i have 100 buttons, theres no way i can use the above step.
I have:
while(numButton<100){
JButton button = new JButton(words);
...
jpanel.add(button);
numButton++;
}
As you see there is no way for me to individually call on one of the buttons, I already have code that auto generates the appropriate variable name for each button, but I do not know how i can change button for something else. Then i heard of java.lang.reflect.Field, but I'm not too sure(even after looking it up), on how it works, and whether or not if it can solve my problem. Can someone show me the way?
If that wont help me is there another way?
heres another one of my illustrations to get my meaning clear:
while(numButton<100){
JButton bu_array[num] = new JButton(words);
num++;
...

the above code doesn't work of course, but it illustrates the idea that i want a different variable name assigned to the button on every loop.

thanks!
 
You posted this question twice. If you have an open thread about a related issue, post to it instead of creating a new thread. This should only be after a google search and looking through the previous posts to see if there is a similar topic already.

[plug=shameless]
[/plug]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top