I am having two forms, 1st is form_1 and 2nd is form_2. form_1 containing one textfield photo_id_num. I am getting its value by .getText method.
public String getID()
{
String id1=photo_id_num.getText();
return(id1);
}
Now I want to access this value into 2nd form. Code for 2nd form is
Form_1 frm=new Form_1();
String id2=frm.getID();
System.out.println("ID2="+id2);
but it doesn’t work. Please help me.
It’s because you are creating a new
Form_1before you callgetIdon it. You need to use theJTextFieldthat was already created and use it to set the Form’s ID. Look in the generated code for the variable name of the text field and get the text from that field. Use that text to set the ID in the form and then call getId on form_1 and use what’s returned in a setText for the other field.Edit Looking at your getId again I see that you have a design issue. Read up about coupling and cohesion. It will make your life much easier.