J2ME: перенаправление на страницу предупреждений

Я создаю приложение на J2ME. У меня есть одна Loginpage и SearchingAccount страница.

Я вставляю 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;
}

person Sandip Armal Patil    schedule 07.05.2012    source источник


Ответы (1)


Если я прав, ваш код сгенерирован автоматически. Вам нужно написать весь код вручную, а затем просто вызвать функцию (которая покажет следующую форму) при нажатии Command.

И внутри этой формы вы должны написать display.setCurrent(Form Name). Но не забудьте добавить виджет к определенной форме.

person Pavan Gomladu    schedule 15.05.2012