0

Here is the JFrame that I put my username in

JButton submit_btn = new JButton("Submit");
submit_btn.setBackground(Color.LIGHT_GRAY);
submit_btn.setFont(new Font("Tahoma", Font.BOLD, 15));
submit_btn.setForeground(Color.BLACK);
submit_btn.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
        String username = user_textfield.getText();
        String password = password_textfield.getText();

        try {
            App_body app = new App_body();
            app.setVisible(true);   
            app.setData(username);
            DesktopApp frame = new DesktopApp();
            app.setData(username);
            dispose(); ....
        }

and here is the JFrame that I want to get the data from

private String data;
void setData(String data1) {
    data = data1;
}

I want to use the information submitted in the first JFrame in the second one but I don't know how to get them.

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
unknown
  • 11
  • 3
  • 3
    Consider using one `JFrame` and one `JDialog`. Search for the words ___jdialog login___ Maybe also this will help? [How can I add a login screen to an existing Java Swing program?](https://stackoverflow.com/questions/15908275/how-can-i-add-a-login-screen-to-an-existing-java-swing-program) Or maybe this [Java Swing: How can I implement a login screen before showing a JFrame?](https://stackoverflow.com/questions/7323086/java-swing-how-can-i-implement-a-login-screen-before-showing-a-jframe/20286447#20286447) – Abra Sep 28 '20 at 21:18
  • The first comment is specific to your problem but correct of course. You seem to be having some more fundamental trouble with Java itself. Please look up the difference between `private` and [public](https://www.javatpoint.com/public-keyword-in-java) keywords and look up [Encapsulation and Getter/Setter](https://www.w3schools.com/java/java_encapsulation.asp). – yur Sep 29 '20 at 09:02

0 Answers0