簡體   English   中英

如何從另一個 JFrame 設置 JFrame 的 JTextField 的文本?

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

我有 2 個 JFrame 類:

  1. ViewPatientLogin JFrame,基本上只是用戶輸入患者姓名的框架,然后被帶到顯示患者詳細信息的第二個 JFrame。

  2. 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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM