[英]How to set text of a JTextField of a JFrame from another JFrame?
我有 2 个 JFrame 类:
ViewPatientLogin JFrame,基本上只是用户输入患者姓名的框架,然后被带到显示患者详细信息的第二个 JFrame。
ViewPatient JFrame,显示所有相关的患者信息。
我想要做的是将文本输入到 ViewPatientLogin JFrame 中的 JTextField txtfFullName 设置为 ViewPatient 框架的相应 JTextField 中的文本。
我已将两个 JFrame 的按钮和 jtextfields 设置为 static 和 public。
但是,当我输入按钮 ActionPerformed 代码时,在创建 ViewPatient object 的新实例时,我无法访问 ViewPatient JFrame 中的任何属性。
任何人,请帮忙? 这对我最后一年的投资组合来说是一个非常重要的项目,我真的被困住了。
编辑:这是让我头疼的按钮 ActionPerformed 代码:
private void btnOKActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
ViewPatient x = new ViewPatient();
//cannot access the textfield of x from here
//x.txtfFullName does not even register
}
public class ViewPatient extends JFrame
{
public ViewPatient(String n)
{
txtfFullName=n;
}
}
private void btnOKActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
ViewPatient x = new ViewPatient(patientName);
x.setVisible(true);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.