By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,798 Members | 1,336 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,798 IT Pros & Developers. It's quick & easy.

Indirect access to an Object

P: n/a
Hi,

I'm working on a GUI using many textfields. Which textfield to put
data into depends on data received via a telnet session. To avoid
doing a huge block of if/else if/else if I wondered if it is possible
to access objects indrectly.

What I'm looking for is something like this (simplified):

I have a textfield : jTextFieldBRI21 = new javax.swing.JTextField();

Now I would like to calculate the name of the text field from the
input like:

String xx = "jTextFieldBRI";
String yy = "2";
String zz = "1";

String aa = xx+yy+zz;

and access the textfield in some way:

[aa].setText("connected"); // or what ever syntax should/could be
used.

Can this be done at all ??? or do I have to stick to the endless
if/else if ?

Thanks in advance
Johnny Funder
Jul 17 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
"Johnny Funder" <jo****@funder.nu> wrote in message
news:40****************@news.tele.dk...
Hi,

I'm working on a GUI using many textfields. Which textfield to put
data into depends on data received via a telnet session. To avoid
doing a huge block of if/else if/else if I wondered if it is possible
to access objects indrectly.

What I'm looking for is something like this (simplified):

I have a textfield : jTextFieldBRI21 = new javax.swing.JTextField();

Now I would like to calculate the name of the text field from the
input like:

String xx = "jTextFieldBRI";
String yy = "2";
String zz = "1";

String aa = xx+yy+zz;

and access the textfield in some way:

[aa].setText("connected"); // or what ever syntax should/could be
used.

Can this be done at all ??? or do I have to stick to the endless
if/else if ?

You might store the text fields in an array and/or have a look at
java.util.Map. Please post to comp.lang.java.help in the future for basic
issues or comp.lang.java.programmer for advanced issues.
Jul 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.