📄 loginform.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 LoginForm extends Form implements CommandListener
{
private Command back;
private Command ok;
private TextField userName;
private TextField password;
public LoginForm(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);
this.append(userName);
this.append(password);
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();
Enumeration e = MyLoginMIDlet.userList.elements();
while(e.hasMoreElements())
{
User user = (User)(e.nextElement());
if (un.equals(user.getUserName()) && pwd.equals(user.getPWD()))
{
MyLoginMIDlet.midlet.showWelcomeList(user);
return;
}
}
password.setString(null);
Alert al = new Alert("登录失败", "用户名或密码错误!", null, AlertType.ERROR);
al.setTimeout(2000);
MyLoginMIDlet.midlet.showAlert(al, this);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -