2

我正在 J2ME 中创建一个应用程序。我有一个LoginpageSearchingAccount佩奇。

我在这两页之间插入AlertSuccess和。AlertFailure如果用户登录成功
,他AlertSuccess会在点击警报后重定向到SerachAcount页面。

我成功地做到了,但是当用户输入不正确的详细信息时,我需要显示 AlertFailure并再次显示登录页面,但即使用户输入了不正确的详细信息,我的应用程序也会显示AlertSuccess并显示 页面。SearchAccount

我尝试了很多但没有成功。请给我有关如何执行此操作的任何提示。

这是我的 MIDlet 流程屏幕: 这是我的 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;
}
4

1 回答 1

2

如果我是对的,您的代码是自动生成的。您需要手动编写所有代码,然后只需在命令单击时调用函数(将显示下一个表单)。

在这个表格里面你应该写display.setCurrent(Form Name)。但不要忘记将小部件附加到特定表单。

于 2012-05-15T05:46:01.473 回答