Validate the size of a TextField
import com.planstick.business.User;
import com.planstick.event.PlanStickEvent;
import com.planstick.event.PlanStickEventListener;
import com.planstick.main.OC;
import com.planstick.net.Session;
import com.planstick.utils.Record;
import javax.microedition.lcdui.*;
public class LoginSettings extends Form implements CommandListener{
private TextField pasw = null;
private TextField login = null;
private Command save = new Command("Save", Command.OK, 0);
private Command back = new Command("Back", Command.BACK, 1);
private Command ok = new Command("OK", Command.ITEM, 1);
public LoginSettings(User user) {
super("");
if(user == null){
login = new TextField("Login:", "", 30, TextField.ANY);
pasw = new TextField("Password:", "", 30, TextField.PASSWORD);
} else {
login = new TextField("Login:", user.getLogin(), 30, TextField.ANY);
pasw = new TextField("Password:", user.getPassword(), 30, TextField.PASSWORD);
}
append(login);
append(pasw);
addCommand(save);
if(user != null) {
addCommand(back);
}
setCommandListener(this);
}
public void commandAction(Command c, Displayable displayable) {
if(c == ok) {
}
if(c == back) {
}
if (c == save) {
String log = login.getString();
String psw = pasw.getString();
if(log != null && log.length() > 0 && psw != null && psw.length() > 0) {
//do samething
} else {
error("Login or Password is Empty");
}
}
}
private void error(String errorText) {
Alert al = new Alert("Settings", errorText, null, null);
al.setTimeout(Alert.FOREVER);
al.addCommand(ok);
al.setCommandListener(this);
OC.display.setCurrent(al);
}
}
Leave a Reply
You must be logged in to post a comment.
RSS