简体   繁体   中英

Get Value from JTextArea in Another Class

Here's the problem. I had to fill a TextArea in Class B ( tAreaB ) with a value from TextArea in Class A ( tAreaA ).

I'm doing this in Class A:

tAreaA.setText("Value A");

How can I fill the tAreaB with same value as tAreaA ? I have tried this in ClassB:

String value;
ClassA a = new ClassA();
value = a.tAreaA.getText();
tAreaB.setText(value);

I suppose that you know how works methods, so, the only thing that you need to do is very simple...

Code:

//Class A - button's - ActionListener.
button.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent A){

//Create a empty variable: String, with the name of: value.
String value = "";

//Value, gets the text of the: txtAreaA.
value = txtAreaA.getText();

//Calls the: classB, and create a new object from them.
classB cb = new classB();

//cb.txtAreaB(); is the method who creates a: JFrame, with JTextArea, in classB.
cb.txtAreaB();

//Now, just call the object, and set the text: value.
cb.txtAreaB.setText(value);
}});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM