Solved

how to identifiy JTextField object at runtime, since the reference name is not stored at class file?

Posted on 2007-03-18
5
234 Views
Last Modified: 2007-03-18
hello experts,

understand that for below code:
  JTextField field1 = new JTextField();

field1 will not be stored inside the class file, but only at source code file.

Then how could I identify this object at runtime? In other words, is there any way to give id to "field1" object that can be read at runtime by other codes  (since the reference name "field1", will not be stored at runtime)

Or should I override JTextField into a new class and create a new attributes for id? Is there any for the existing JTextField?

Thanks & regards.
0
Comment
Question by:isuhendro
5 Comments
 

Author Comment

by:isuhendro
ID: 18743341
btw to clarify..
for example

at class A i have code like below:

JPanel myPanel = new JPanel();
JTextField field1  = new JTextField();
JTextField field2  = new JTextField();

myPanel.add(field1);
myPanel.add(field2);

my question is related to an inner class, named class B, inside class A.
Inside class B, I am trying to write code which will return a collection whose members are a pair of fieldname and its value, e.g ("field1", "valueoffield1"), ("field2", "valueoffield2").
The problem is as i told you, i could not get the id "field1", "field2", etc
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 18744098
You could call getComponents on the nearest Container to the JTextField(s) to which you want to get a reference
0
 
LVL 30

Expert Comment

by:mayankeagle
ID: 18744536
You can expose it as a member of the class A:

public JTextField getFirstTextField ()
{
  return field1 ;

}

You can either expose all of them this way (using multiple get methods) to be accessible from outside or create them in an array and expose the array in one method.
0
 
LVL 92

Accepted Solution

by:
objects earned 125 total points
ID: 18745049
0
 
LVL 92

Expert Comment

by:objects
ID: 18745053
eg.  field.setName("field1");
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
This video teaches viewers about errors in exception handling.

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now