views:

386

answers:

1

Below is some code which simply allows a user to log in, however i want to be able to reset the value of the text fields userName and password to nothing in the else statement if the user enters the name or password wrong so that is no longer displays their previously entered details. Can anyone tell me how i do this? Also how do you set the characters of the password field to be * instead of characters so on one can see the entered password.

Many thanks

public class LoginMIDlet extends MIDlet implements CommandListener {

    private boolean midletPaused = false;

    //<editor-fold defaultstate="collapsed" desc=" Generated Fields ">
    private Form SignIn;
    private TextField userName;
    private TextField password;
    private StringItem sim_Result;
    private Form Continue;
    private Command _login;
    private Command _cancel;
    private Command okCommand;
    //</editor-fold>

    /**
     * The LoginMIDlet constructor.
     */
    public LoginMIDlet() {
    }

     public void validateUser(String user, String password) {
     if (user.equals("qm") && password.equals("j2")) {
         switchDisplayable(null, getContinue());
     } else {
         switchDisplayable(null, getSignIn());
         sim_Result.setText("You have entered an Incorred Username Or Password, Please Try Again");
     }
}
+1  A: 

Can you not use the setString() method of the TextField class? Call it with an empty string "", that will clear the field.

On the password hiding, set constraints on the field, either at construction or after. See the TextField javadocs for more detail.

Example:

password.setConstraints( TextField.PASSWORD );
martin clayton