I've got this big multiple class application, and i've got alogin system. So after a user logs in the text "Welcome, Guest" should update do "Welcome, username". My method "logininfo" is the one handling it and it uses the method setText(). You can see the method here:
public void loginInfo(String userName) {
lblWelcomeGuest.setText("Welcome, "+userName);
System.out.println(lblWelcomeGuest.getText());
}
The GUI shows "Welcome, Guest", while my debug-message prints "Welcome, Fillefixsweden". I have no idea what the problem is, maybe I need to refresh? Please help!
Requested by comments, whole code (without imports):
public class MainGUI extends JFrame{
private static final long serialVersionUID = 1L;
LogIn login= new LogIn();
private JLabel lblWelcomeGuest = new JLabel("Welcome, Guest");
public String uName;
private JLabel lblLogIn = new JLabel("Log in");
LoginUI loginui = new LoginUI();
public void initialize() {
lblLogIn.setFont(new Font("Tahoma", Font.PLAIN, 14));
lblLogIn.setForeground(Color.WHITE);
lblLogIn.setBounds(842, 118, 128, 14);
lblWelcomeGuest.setBounds(10, 116, 133, 16);
lblWelcomeGuest.setFont(new Font("Tahoma", Font.PLAIN, 13));
lblWelcomeGuest.setForeground(Color.WHITE);
getContentPane().add(lblWelcomeGuest);
getContentPane().add(lblLogIn);
}
public void loginInfo(String userName) {
lblWelcomeGuest.setText("Welcome, "+userName);
lblLogIn.setText("Log out");
System.out.println(lblWelcomeGuest.getText());
}
}
Here is the complete Main class:
public class Main {
MainGUI gui;
public String username;
public Main() {
System.out.println("Main constructor");
gui = new MainGUI();
gui.initialize();
gui.setVisible(true);
}
public static void main(String[] args) {
System.out.println("Main");
new Main();
}
}
And here is the method that calls loginInfo() (another class):
public void cred(String name, String password){
if(new SQL().validate(name, password)){
System.out.println("Logged in");
CloseFrame();
new MainGUI().loginInfo(name);
}else{
System.out.println("Credentials does not match!");
System.out.println(name+" "+password);
}
}