I have a method in Layout
class which return a String
from JTextField
. When I call sout
to check that String
isn't empty, and console returns the text entered to JTextField
, but when I invoke in other class the same method, the String
is null.
public String name;
private void loginButtonListener(){
loginButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) {
if(validatePassword()) {
menuBar.setVisible(true);
setFundsLabel(getFunds());
setAccWelcome("Welcome back, " + getAccountName() + "!");
cl.show(cards,"acc");
name = getAccountName();
System.out.println("getNameAcc: ");
System.out.println("-----------------");
//System.out.println(getNameAcc());
System.out.println("-----------------");
}
else
JOptionPane.showMessageDialog(loginPanel, "Incorrect login or password", "Error", 3);
}
});
}
public String getNameAcc(){
return name;
}
That's a class where the String name
works.
final String SENDER_PATH = t.DATA+ File.separator+t.FUNDS+File.separator+ l.getNameAcc() +FUNDS_TXT;
System.out.println(SENDER_PATH);
That's a extract of second class where the getNameAcc
doesn't work. (this is invoke in void method by actionListener on button).
Where I have a mistake?