0

so i have 2 form 1 form is from a login form and the second is the home form so right after the user login it will show the home form but here i want to take the string in the login username textfield and use it at the home form in a label that says Welcome and the name from the username textfield from the login here is my code

public class Admin_Home extends javax.swing.JFrame {
    /**
     * Creates new form Admin_Home
     */
    AdminLogin_Form login = new AdminLogin_Form();
    String username = login.getUsername();
    public Admin_Home() {
        initComponents();
    }
    
    public void homeWelcome(){
        jLabel2.setText("Welcome " + username);
    }

can anybody help me in this kind of problem ? any solutions?

  • 4
    Please provide a [mre] of your problem. Usually, having two seperate `JFrame`s is considered bad practice, as it is not user friendly, see https://stackoverflow.com/questions/9554636/the-use-of-multiple-jframes-good-or-bad-practice. You should use a [`CardLayout`](https://docs.oracle.com/javase/tutorial/uiswing/layout/card.html) instead. – maloomeister Sep 29 '21 at 10:08
  • 5
    1) [Edit] to add a [mre]. 2) But the mention of 'forms' makes me think they are both `JFrame` windows, when one should be a modal `JDialog`. 3) Give components better (more descriptive) names than `jLabel2`. 4) Don't extend components and windows unless adding new functionality or changing existing functionality. – Andrew Thompson Sep 29 '21 at 10:08
  • 1
    You need to invoke the *String username = login.getUsername();* statement AFTER the user has entered the name and the login form has been closed. – camickr Sep 29 '21 at 13:48

0 Answers0