[英]How to pass data from a JTextField to another JTextField
I need to pass a text from a JTextField in a JFrame to a second JTextField in another JFrame. 我需要将文本从JFrame中的JTextField传递到另一个JFrame中的第二个JTextField。 GUI has been created using GUI Editor netbeans 6.9.
GUI是使用GUI编辑器netbeans 6.9创建的。
getText()
of the first JTextField and setText()
on the second field. getText()
和第二个字段的setText()
成为可能。 Use textField.getText to get the text from a textfield and anotherTextField.setText to set the text of the other textfield. 使用textField.getText从一个文本字段获取文本,并使用anotherTextField.setText设置另一个文本字段的文本。
If your JFrames are in two different classes you may have to expose methods in those classes to get and set the text between them. 如果您的JFrame位于两个不同的类中,则可能必须在这些类中公开方法以获取并设置它们之间的文本。
You should bind your model to both of the views (JTextFields) instead of copying Text from one to another. 您应该将模型绑定到两个视图(JTextFields),而不是将Text从一个视图复制到另一个视图。
Read http://www.martinfowler.com/eaaDev/OrganizingPresentations.html for more information. 阅读http://www.martinfowler.com/eaaDev/OrganizingPresentations.html以获得更多信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.