0

I want to access JTextField of a class from another class , From the new class i want to setText to the textField.

from class patient_details i want to access the JTextField present in class Admission_screen. This is code which i used in patient_details class to add text in text field present in admission_screen class.

 Admission_screen admit=new Admission_screen();
                 admit.t2.setText("xxx");

t2 is the textfiels present in admission_screen class.

this is not working help me with your suggestions

dheena
  • 85
  • 3
  • 6
  • 15
  • Something like [this example](http://stackoverflow.com/questions/28653892/java-swing-how-to-get-the-value-of-text-in-a-textfield-from-another-class/28654237?noredirect=1#comment45627572_28654237)? – MadProgrammer Feb 23 '15 at 04:52
  • 1) *"I want to access JTextBox.."* There's no such class in the J2SE. 2) *"help me with ur suggestions"* I suggest you spell words like 'your' properly and check class names before posting. – Andrew Thompson Feb 23 '15 at 04:58
  • sry .... its Textfield – dheena Feb 23 '15 at 05:01

1 Answers1

0

Add this method to Admission_screen:

public void setT2Text(String text){
    t2.setText(text);
}

Call it using the admit object you created. Like so: admit.setT2Text("txt");

Dando18
  • 622
  • 9
  • 22
  • your right @Dando18 .......... but I made mistake by creating two objects for one class .... your answer was helpful for me find my mistake ...thank you – dheena Feb 23 '15 at 06:39