2
我正在J2ME中創建一個應用程序。我有一個Loginpage
和SearchingAccount
頁面。我在這兩頁之間插入了AlertSuccess
和AlertFailure
。如果用戶成功登錄
他點擊警報後重定向AlertSuccess
他將重定向到SerachAcount
頁面。J2ME:重定向到Alert頁面
我成功做到這一點,但是當用戶輸入不正確的信息,然後我需要顯示AlertFailure
並顯示重新登錄的頁面,但我的應用程序顯示AlertSuccess
並顯示SearchAccount
頁,即使用戶輸入不正確的信息。
我嘗試了很多,但沒有成功。請給我任何關於如何做到這一點的提示。
這裏是我的MIDlet流程屏幕:
這裏是我的參考代碼。
} else if (displayable == Login) {
if (command == Login1) {
u_Name=txtUserId.getString();
u_Password=txtPassword.getString();
readUserRecords(u_Name, u_Password);
switchDisplayable(null, getWaitScreen());
public void readUserRecords(String userName,String Password){
try{
byte[] recData = new byte[5];
int len;
for(int i = 1; i <= rs.getNumRecords(); i++){
if(rs.getRecordSize(i) > recData.length){
recData = new byte[rs.getRecordSize(i)];
}
len = rs.getRecord(i, recData, 0);
String str= new String(recData,0,len);
s=str.indexOf(userName);
s1=str.indexOf(Password);
splitUserRecord(str);
System.out.println("User Login Page--------------------------------------");
System.out.println("---index of string-------"+s+" and "+s1);
if(u_id.equals(u_Name)&& u_pass.equals(u_Password))
{
System.out.println("UserLogin Successfully "+str);
alertSuccess = new Alert("OK", "You are Login Successfully!",
successimg, AlertType.INFO);
alertSuccess.setImage(successimg);
display.setCurrent(alertSuccess, Login);
}
else
{
System.out.println("Enter Wrong user name");
alertFailure = new Alert("Cancel", "Enter correct user name and password!",failureimg, AlertType.INFO);
System.out.println("Enter Wrong user name1");
alertFailure.setImage(failureimg);
System.out.println("Enter Wrong user name2");
display.setCurrent(alertFailure, Login);
System.out.println("Enter Wrong user name3");
// getAlertFailure();
}
}
}catch (Exception e){}
}
public Alert getAlertFailure() {
if (alertFailure == null) {
alertFailure = new Alert("alert");
alertFailure.setTimeout(Alert.FOREVER);
alertFailure.setImage(failureimg);
display.setCurrent(alertFailure,Login);
}
return alertFailure;
}
public Alert getAlertSuccess() {
if (alertSuccess == null) {
alertSuccess = new Alert("alert1");
alertSuccess.setTimeout(Alert.FOREVER);
}
return alertSuccess;
}
嘿謝謝...這很簡單,但解決了我的問題。 –