I have Jframe that has a JTextField and a JButton. It should return text of Jtextfield to anotherClass (MainPage). 
but when program starts, It returns null to the class. 
    public class JframeFoo extends JFrame {
    private String username = new String();
    public JframeFoo() {
        // --------------------------------------------------------------
        // Making Frame for login
        final JTextField usernameFiled = new JTextField();
        this.add(usernameFiled);
        JButton signinButton = new JButton();
        // ------------------------------------------------------------
        signinButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent arg0) {
                setVisible(false);
                Main.mainpage.setVisible(true);
            }
        });
        // ----------------------------------------------------------------------
        username = usernameFiled.getText();
    }
    public String getuserName() {
        return this.username;
    }
}
(this Jframe should run at the start of program and when it gets text, it should go to invisible and another class should become visible.)
 
     
     
     
    