[英]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
). 我不得不补
TextArea
在B类( tAreaB
与来自的值) TextArea
(在A类tAreaA
)。
I'm doing this in Class A: 我在A类中这样做:
tAreaA.setText("Value A");
How can I fill the tAreaB
with same value as tAreaA
? 如何用与
tAreaB
相同的值填充tAreaA
? I have tried this in ClassB: 我已经在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);
}});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.