简体   繁体   English

如何从另一个 JFrame 设置 JFrame 的 JTextField 的文本?

[英]How to set text of a JTextField of a JFrame from another JFrame?

I have 2 JFrame classes:我有 2 个 JFrame 类:

  1. The ViewPatientLogin JFrame, which is basically just a frame where the user inputs a Patient's name, and is then taken to the second JFrame where the Patient's details are displayed. ViewPatientLogin JFrame,基本上只是用户输入患者姓名的框架,然后被带到显示患者详细信息的第二个 JFrame。

  2. The ViewPatient JFrame, which displays all of the relevant Patient info. ViewPatient JFrame,显示所有相关的患者信息。

What I want to do is to have the text input into the JTextField txtfFullName in the ViewPatientLogin JFrame be set as the text in the ViewPatient frame's corresponding JTextField.我想要做的是将文本输入到 ViewPatientLogin JFrame 中的 JTextField txtfFullName 设置为 ViewPatient 框架的相应 JTextField 中的文本。

I have set the buttons and jtextfields of both JFrames to static and public.我已将两个 JFrame 的按钮和 jtextfields 设置为 static 和 public。

However, when I enter the button ActionPerformed code, upon creating a new instance of the ViewPatient object, I cannot access any of the attributes in the ViewPatient JFrame.但是,当我输入按钮 ActionPerformed 代码时,在创建 ViewPatient object 的新实例时,我无法访问 ViewPatient JFrame 中的任何属性。

Anyone, please help?任何人,请帮忙? This is a really important project for my final year portfolio, and I'm really stuck.这对我最后一年的投资组合来说是一个非常重要的项目,我真的被困住了。

EDIT: Here is the button ActionPerformed code that's giving me a headache:编辑:这是让我头疼的按钮 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.

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