📄 registerform.java
字号:
import java.io.IOException;
import java.util.Enumeration;
import javax.microedition.lcdui.Alert;
import javax.microedition.lcdui.AlertType;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.TextField;
//注册界面
public class RegisterForm extends Form implements CommandListener
{
private Command back;
private Command ok;
private TextField userName;
private TextField password;
private TextField passwordCon;
private TextField realName;
private TextField age;
public RegisterForm(String title)
{
super(title);
back = new Command("返回", Command.BACK, 1);
ok = new Command("确定", Command.OK, 1);
userName = new TextField("*用户名:", null, 20, TextField.ANY);
password = new TextField("*密码:", null, 20, TextField.PASSWORD);
passwordCon = new TextField("*确认密码:", null, 20, TextField.PASSWORD);
realName = new TextField("真实姓名:", null, 20, TextField.ANY);
age = new TextField("年龄:", "0", 20, TextField.NUMERIC);
this.append(userName);
this.append(password);
this.append(passwordCon);
this.append(realName);
this.append(age);
this.addCommand(back);
this.addCommand(ok);
this.setCommandListener(this);
}
public void commandAction(Command c, Displayable d)
{
if (c.equals(back))
{
MyLoginMIDlet.midlet.showMainList();
}
else if (c.equals(ok))
{
String un = userName.getString();
String pwd = password.getString();
String pwdCon = passwordCon.getString();
String rn = realName.getString();
int age = Integer.parseInt(this.age.getString());
if("".equals(un) || un==null)
{
Alert al = new Alert("错误", "用户名不能为空!", null, AlertType.ERROR);
al.setTimeout(2000);
MyLoginMIDlet.midlet.showAlert(al, this);
return;
}
if (!pwd.equals(pwdCon))
{
Alert al = new Alert("错误", "确认密码错误!", null, AlertType.ERROR);
al.setTimeout(2000);
MyLoginMIDlet.midlet.showAlert(al, this);
return;
}
Enumeration e = MyLoginMIDlet.userList.elements();
while(e.hasMoreElements())
{
User user = (User)(e.nextElement());
if (un.equals(user.getUserName()))
{
Alert al = new Alert("错误", "用户名已存在!", null, AlertType.ERROR);
al.setTimeout(2000);
MyLoginMIDlet.midlet.showAlert(al, this);
return;
}
}
User user = new User(un, pwd, rn, age);
MyLoginMIDlet.userList.addElement(user);
Alert al = new Alert("恭喜", "恭喜"+un+"注册成功!", null, AlertType.INFO);
al.setTimeout(2000);
MyLoginMIDlet.midlet.showAlert(al, MyLoginMIDlet.midlet.getMainList());
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -