Dynamically adding form elements to a frame

Hay I have to add form elements to a frame dynamically in a loop.But I have a problem in instantiating those form elements wiz.

String[] s={"a","b","c"};

for(int i=0;i<s.length;i++)

{

JButton s.=new JButton();

this.getcontentPane().add(s);

}

can any body help me in this

>

[354 byte] By [Srikrishna_B] at [2007-9-26 2:41:11]
# 1

**correction for the earlier**

Hay I have to add form elements to a frame dynamically in a loop.But I have a problem in instantiating those form elements wiz.

String[] s={"a","b","c"};

for(int i=0;i<s.length;i++)

{

JButton s=new JButton();

this.getcontentPane().add(s);

}

>

Srikrishna_B at 2007-6-29 10:16:25 > top of Java-index,Archived Forums,Swing...
# 2
For one thing, your String[] is called "s" and your JButton components are also called "s". You need to change that!
darrelln at 2007-6-29 10:16:25 > top of Java-index,Archived Forums,Swing...
# 3

Notice that using array index "i" screws up the formatting of your post. It makes the font switch to italics! Anyway...I think what you want to be doing is this:

String[] s={"a","b","c"};

for(int j=0 ; j<s.length ; j++) {

JButton b = new JButton(s[j]);

this.getcontentPane().add(b);

}

>

darrelln at 2007-6-29 10:16:25 > top of Java-index,Archived Forums,Swing...