Solved

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

Posted on 2007-03-18
5
252 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:Mayank S
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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Basic Java Case or If-Else statement... 3 51
Android development question 2 37
eclipse console opening separately 2 21
Crystal Reports Licensing Questions 4 12
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

809 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