newbie needs your help! (JTextField)

N

Newbie

can some kind soul please help me out here?

I want to create 12 JTextFields.

I could of course write all 12 seperately like:

JTextField display1 = new JTextField();
JTextField display2 = new JTextField();
...
...
JTextField display12 = new JTextField();

Is there a way I can do this dynamically in a 'for loop'?

I have tried this, but it doesnt seem to work as I hoped for:

for (int x=0; x < 12; x++)
{
JTextField display+x = new JTextField();
}

Is there a way around what I would like to achieve?

thankyou!
 
A

ak

create array of JTextFields:
JTextField [] fields = new JTextField[12];
for(int i = 0; i < fields.length; i++) {
fields = new JTextField();
}
 
V

VisionSet

Newbie said:
can some kind soul please help me out here?

I want to create 12 JTextFields.
I could of course write all 12 seperately like:
...
Is there a way I can do this dynamically in a 'for loop'?

I have tried this, but it doesnt seem to work as I hoped for:

for (int x=0; x < 12; x++)
{
JTextField display+x = new JTextField();
}

Is there a way around what I would like to achieve?

JTextField[] f = new JTextField[12];
for(int i=0;i<f.length;i++) {
f = new JTextField();
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,433
Messages
2,571,683
Members
48,796
Latest member
Greg L.

Latest Threads

Top