Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SETTING FIELD IN ANOTHER CLASS

Status
Not open for further replies.

eh171

Programmer
Feb 21, 2003
9
GB
I have 3 classes: class1 extends Jpanel, class2 extends Jpanel, class3 extends JFrame. What I am trying to do is set the textfields in class1 from class2 according to user input: user enters an ID and presses a button (in another frame: class4) and data relating to that ID e.g. name, number... is retrieved from the server and then the fields in class1 are set to these values from class2. I have the following coding

class 1
JTextfield nameField = new JTextField()

class1 constructor(
panel.add(nameField)

class2
class1 c1 = new class1()
c1.clTextField.setText(...)
panel.add(c1)

class 3 constructor
panel.add(class2Object);

when the user enters an ID (in class4)and presses enter the correct data is displayed. However when I close down the class3 frame and enter another ID the frame gets displayed but all the textFields have gone missing????????

p.s. what is the difference between creating a new object and invoking it on the textfield e.g.(in class1)
class2 c2 = new class2
c2.textFieldInClass2

and stating the textfield as a static string in class2 and then just invoking class2Name on it in class1 e.g.
class2Name.textfield
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top