尝试借助 Java Class 将数据从一个 jFrame 传输到另一个 jFrame

Trying to transfer data from one jFrame to another jFrame with the help of a Java Class

我正在尝试使用单独的 java Class 将一个 jFrame 中获取的电子邮件和密码数据传输到另一个 jFrame。 全部在同一个包中。非常感谢任何帮助,这是我的第一个问题,所以不知道要提及的具体细节,所以如果您需要,请告诉我。

LoginForm.java(第一个 jFrame)

存在数据操作的部分此处String mail,pass;有电子邮件和密码数据

    if(op==true) {
                 JOptionPane.showMessageDialog(null, "Login Successful!", "WebApp Database Login",
                 INFORMATION_MESSAGE);
                 DataTransfer dt=new DataTransfer();      // Setting instance of DataTransfer class 
                                                            //to pass on Mail and Password details
                 dt.setEmail(mail);
                 dt.setPassword(pass);
                 InfoDisplay id=new InfoDisplay();
                 id.setVisible(true);
                 }

DataTransfer.java

    public class DataTransfer {
        private String loginEmail;
        private String loginPassword;

        public String getEmail() {
            return loginEmail;
        }
    
        public String getPassword() {
            return loginPassword;
        }
    
        public void setEmail(String email) {
            loginEmail=email;
            System.out.println("Stored Mail: "+loginEmail);
        }
    
        public void setPassword(String password) {
            loginPassword=password;
            System.out.println("Stored Pass: "+loginPassword);
        } }

InfoDisplay.java(第 2 个 jFrame)

//构造函数

    public InfoDisplay() {
        initComponents();
        //Displaying Current Date and Time
        Calendar cl=Calendar.getInstance();
        String datetime=cl.getTime().toString();
        jLabel5.setText(datetime);
        //Getting the Stored details of Mail and Password from DataTransfer class
        DataTransfer dt=new DataTransfer();
        String finalEmail=dt.getEmail();
        String finalPass=dt.getPassword();
        System.out.println("Email: "+finalMail);
        System.out.println("Password: "+finalPass); }

我使用打印命令来检查它们是否被正确分配。我是 运行 仅来自 LoginForm.java 的程序,数据存储在 DataTransfer.java 中,但它显示 Email: NULLPassword: NULL 中的值信息显示()

我用它工作....

LoginForm.java

public class LoginForm {
    public static void main(String[] args) {
        DataTransfer dataTransfer = new DataTransfer();
        dataTransfer.setEmail(mail);
        dataTransfer.setPassword(pass);
        InfoDdisplay infoDdisplay = new InfoDdisplay(dataTransfer);
    }
}

InfoDisplay.java

public class InfoDisplay {
    public InfoDisplay(DataTransfer dt) {
        //Displaying Current Date and Time
        //Getting the Stored details of Mail and Password from DataTransfer class
        String finalEmail = dt.getEmail();
        String finalPass = dt.getPassword();
        System.out.println("Email: " + finalEmail);
        System.out.println("Password: " + finalPass);
    }
}

DataTransfer.java

public class DataTransfer {
    private String loginEmail;
    private String loginPassword;

    public String getEmail() {
        return loginEmail;
    }

    public String getPassword() {
        return loginPassword;
    }

    public void setEmail(String email) {
        loginEmail=email;
        System.out.println("Stored Mail: "+loginEmail);
    }

    public void setPassword(String password) {
        loginPassword=password;
        System.out.println("Stored Pass: "+loginPassword);
    } 
}