2012-05-07 45 views
2

我正在J2ME中創建一個應用程序。我有一個LoginpageSearchingAccount頁面。我在這兩頁之間插入了AlertSuccessAlertFailure。如果用戶成功登錄
他點擊警報後重定向AlertSuccess他將重定向到SerachAcount頁面。J2ME:重定向到Alert頁面

我成功做到這一點,但是當用戶輸入不正確的信息,然後我需要顯示AlertFailure並顯示重新登錄的頁面,但我的應用程序顯示AlertSuccess並顯示SearchAccount頁,即使用戶輸入不正確的信息。

我嘗試了很多,但沒有成功。請給我任何關於如何做到這一點的提示。

這裏是我的MIDlet流程屏幕: Here is my MIDlet flow screen.

這裏是我的參考代碼。

} 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; 
} 

回答

2

如果我是對的,你的代碼是自動生成的。您需要手動編寫所有代碼,然後在Command單擊時調用該函數(將顯示下一個表單)。

而在這個表格裏你應該寫display.setCurrent(Form Name)。但不要忘記將小部件附加到特定的表單。

+0

嘿謝謝...這很簡單,但解決了我的問題。 –