GetText for another class file in java

Asked 2 years ago, Updated 2 years ago, 35 views

Create a text field in sample1.java with JTextField text=newJTextField(); and press the button to move another class (textget) program in sample2.java. I wrote (wanted) a program to get a string in the text field in getText(), but simply cannot get a string from the String=text;text(text);Please tell me how to write it.

java

2022-09-30 20:17

1 Answers

It is difficult to getText() the text fields of another class.
In sample1.java, add a method to retrieve the text field and place

String str=this.text.getText();
return str;

I think you can do it if you write thatAfter that, I think you can call from sample2.java.
Of course, there will be an error in this case, so the sample1.java field will be

JTextField text=newJTextField();

I think I can compile it if I write like this.


2022-09-30 20:17

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.