0
但在另一個類的設置方法,當我得到的值是存在,, 所以我有3個類的第一類是getter setter類,第二個是類填充集和最後一個類是獲得方法吸氣,,但它會空值...爲什麼當我在另一個班級打電話時,getter方法變爲空?
public class loginAdminn {
String Username, Password;
public String getUsername() {
return Username;
}
public void setUsername(String Username) {
this.Username = Username;
}
public String getPassword() {
return Password;
}
public void setPassword(String Password) {
this.Password = Password;
}
}
// method to fill the set on another class
public void in(){
loginAdminn p = new loginAdminn();
String user = Username.getText();
String pass = Password.getPassword().toString();
p.setUsername(user);
p.setPassword(pass);
// new NewMain().run();
tes.jalankan();
}
// class method getter (null)
public void jalankan() {
loginAdminn br = new loginAdminn();
String kueri = "Select Username, password from Admin";
int x = 0;
try {
ps = conn.prepareStatement(kueri);
ResultSet rs = ps.executeQuery();
while (rs.next()) {
if (br.getUsername().equalsIgnoreCase(rs.getString("Username"))) {
if (br.getPassword().equalsIgnoreCase(rs.getString("Password"))) {
JOptionPane.showMessageDialog(null, "Masuk Berhasil");
x = 1;
break;
}
}
}
if (x == 1) {
HomeAdmin b = new HomeAdmin();
b.setVisible(true);
} else {
JOptionPane.showMessageDialog(null, "Masuk Gagal");
DaftarAplikasi da = new DaftarAplikasi();
da.setVisible(true);
}
ps.close();
} catch (SQLException ex) {
JOptionPane.showMessageDialog(null, ex.getMessage());
}
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
//the getUsername and getPassword goes null
我將br與訪問值進行比較,那麼訪問者的值是多少? –
訪問器方法應該在一個類中聲明嗎?所以只有2班? –
或者我應該輸入參數? –