There are many ways you could achieve this. The simplest would be to pass the object into the method in class B:
public void doSomething(JTextField fieldToUpdate){
//your logic here
fieldToUpdate.setText("something");
}
Then you can just update fieldToUpdate directly. This is not a great design pattern since it directly exposes control of a variable owned by 1 class to another.
Another alternative is to pass the instance of Class A into the method and call public methods on it:
public void doSomething(A aInstance){
//your logic here
aInstance.setText("something");
}
then in class A you'd need to define
public void setText(String text){
txtField1.setText(text);
}
This is a little better since class B doesn't have direct access to the internals of Class A.
An even more encapsulated response (though probably overkill for a case this simple) is to define an Interface and pass an instance of a class that implements the interface to the method in class B:
public void doSomething(TextDisplayer txt){
//your logic here
txt.setText("something");
}
then in class a:
public class A implements TextDisplayer{
public void setText(String txt){
txtField1.setText(txt);
}
}
then the interface:
public interface TextDisplayer{
public void setText(String txt);
}
The advantage of this approach is that it keeps class B completely decoupled from the class A. All it cares about is that it is passed something that knows how to handle the setText method. Again, in this case it is probably overkill, but it is the approach that keeps your classes as decoupled as possible.