给定一个登录窗口,它需要来自用户的2个输入:用户名&密码。 成功识别后,用户将被重定向到主窗口。 在这里,我想显示他或她的用户名,但我收到空。JAVA - 在类之间传递值
这是我当前的代码: 登录类:
private void LoginUser(String username, String password)
{
user = username;
pass = password;
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
try
{
conn = MainEngine.getConnection();
stmt = conn.createStatement();
rs = stmt.executeQuery("SELECT username FROM users WHERE username ='"+user+"' AND password ='"+getMD5Hex(pass)+"'");
if(rs.next()) // Successful login
{
Window_AfterLogin window_afterlogin = new Window_AfterLogin();
window_afterlogin.setVisible(true);
this.dispose();
}
else
{
label_info.setText("Wrong credentials");
}
}
catch(Exception e)
{
System.err.println(e);
}
}
public String getUserName()
{
return user;
}
注:用户并传递变量是全球性的。
Window_AfterLogin类:
public Window_AfterLogin() {
initComponents();
Window_Login window_login = new Window_Login();
System.out.println(window_login.getUserName());
}
*对不起,我在标题 – Unrealxqt
*您可以编辑您的问题,并更改标题的不必要的“中”字... –
哪里是主窗口的代码? – sForSujit