FileDocCategorySizeDatePackage
LoginMidlet.javaAPI DocExample2123Sat Jan 05 11:47:24 GMT 2002None

LoginMidlet

public class LoginMidlet extends javax.microedition.midlet.MIDlet implements CommandListener

Fields Summary
private Display
display
private TextField
userName
private TextField
password
private Form
form
private Command
cancel
private Command
login
Constructors Summary
public LoginMidlet()

      userName = new TextField("LoginID:", "", 10, TextField.ANY);
      password = new TextField("Password:", "", 10, TextField.PASSWORD);
      form = new Form("Sign in");
      cancel = new Command("Cancel", Command.CANCEL, 2);
      login = new Command("Login", Command.OK, 2);
   
Methods Summary
public voidcommandAction(Command c, Displayable d)

      String label = c.getLabel();
      if(label.equals("Cancel")) {
        destroyApp(true);
      } else if(label.equals("Login")) {
         validateUser(userName.getString(), password.getString());
      }
   
public voiddestroyApp(boolean unconditional)

      notifyDestroyed();
   
public voidmenu()

     List services = new List("Choose one", Choice.EXCLUSIVE);
     services.append("Check Mail", null);
     services.append("Compose", null);
     services.append("Addresses", null);
     services.append("Options", null);
     services.append("Sign Out", null);
     display.setCurrent(services);
   
public voidpauseApp()

   
public voidstartApp()

      display = Display.getDisplay(this);
      form.append(userName);
      form.append(password);
      form.addCommand(cancel);
      form.addCommand(login);
      form.setCommandListener(this);
      display.setCurrent(form);
   
public voidtryAgain()

     Alert error = new Alert("Login Incorrect", "Please try again", null, AlertType.ERROR);
     error.setTimeout(Alert.FOREVER);
     userName.setString("");
     password.setString("");
     display.setCurrent(error, form);
   
public voidvalidateUser(java.lang.String name, java.lang.String password)

     if (name.equals("qm") && password.equals("j2")) {
       menu();
     } else {
       tryAgain();
     }