?? loginmidlet.java
字號:
package com.j2medev.chapter4;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
public class LoginMIDlet extends MIDlet implements CommandListener {
private Display display;
private Form loginForm;
private Form successForm;
private TextField userName;
private TextField password;
private ChoiceGroup autoLogin;
private Model model;
public static final Command connCommand = new Command("登錄", Command.OK, 1);
public static final Command exitCommand = new Command("退出",Command.EXIT,2);
protected void startApp() {
initMIDlet();
Account account = model.getAccount(1);
if (account == null || !account.isAutoLogin()) {
display.setCurrent(loginForm);
} else if (account.isAutoLogin()) {
//讀取RMS中的用戶和密碼與服務(wù)器端校驗(yàn),這里省略。
display.setCurrent(successForm);
}
}
public void initMIDlet() {
model = new Model();
display = Display.getDisplay(this);
loginForm = new Form("用戶登錄");
userName = new TextField("用戶名:", null, 20, TextField.ANY);
password = new TextField("密碼:", null, 20, TextField.PASSWORD);
autoLogin = new ChoiceGroup("設(shè)置", Choice.MULTIPLE,
new String[] { "自動登錄" }, null);
loginForm.append(userName);
loginForm.append(password);
loginForm.append(autoLogin);
loginForm.addCommand(connCommand);
loginForm.addCommand(exitCommand);
loginForm.setCommandListener(this);
successForm = new Form("登錄成功");
successForm.addCommand(exitCommand);
successForm.setCommandListener(this);
successForm.append("您已經(jīng)成功連接到服務(wù)器!");
}
protected void pauseApp() {
}
protected void destroyApp(boolean arg0) {
model.closeRecordStore();
}
public void commandAction(Command cmd, Displayable displayable) {
String _userName;
String _password;
boolean auto = false;
if (cmd == connCommand) {
_userName = userName.getString();
_password = password.getString();
auto = autoLogin.isSelected(0);
if (auto) {
Account account = new Account(_userName, _password, auto);
model.saveAccount(account);
}
display.setCurrent(successForm);
}else if(cmd == exitCommand){
destroyApp(false);
notifyDestroyed();
}
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -