📄 00e5c7f8f09a001b1a36b107245978e8
字号:
package bankbillClent;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
import shared.AccountInfo;
public class AccountInfoUI extends Form implements CommandListener {
private TextField userNameField;
private TextField passwordField;
private TextField cardHolderNameField;
private TextField cardNumberField;
private Command sendCommand;
private Command backCommand;
private MIDlet midlet;
private Display display;
private Displayable parent;
private ProgressObserverUI progressObserverUI;
public AccountInfoUI(MIDlet midlet,Displayable parent) {
super("登陆");
userNameField = new TextField("用户名:", null, 12, TextField.ANY);
passwordField = new TextField("密码:", null, 20, TextField.PASSWORD);
cardHolderNameField = new TextField("信用卡拥有人:", null, 12, TextField.ANY);
cardNumberField = new TextField("卡号:", null, 30, TextField.NUMERIC);
sendCommand = new Command("发送", Command.OK, 5);
backCommand = new Command("返回", Command.BACK, 5);
this.midlet = midlet;
this.display = Display.getDisplay(midlet);
this.parent = parent;
progressObserverUI = new ProgressObserverUI();
append("请输入你的用户名和密码");
append(userNameField);
append(passwordField);
append(cardHolderNameField);
append(cardNumberField);
addCommand(sendCommand);
addCommand(backCommand);
setCommandListener(this);
}
public void init() {
userNameField.setString(null);
passwordField.setString(null);
}
public void commandAction(Command command, Displayable displayable) {
if(command == sendCommand){
sendInfo(userNameField.getString(), passwordField.getString());
}
if(command == backCommand){
display.setCurrent(parent);
}
}
public void sendInfo(final String userName, final String password) {
Thread thread = new Thread() {
public void run() {
try {
System.out.println("处理用户登陆");
//model.login(userName, password);
BankBillListUI bbui=null;
String url = "http://127.0.0.1:8080/BankBillServlet";
HTTPCommunication hc = new HTTPCommunication(url,progressObserverUI);
//发送用户信息
AccountInfo accinfo = new AccountInfo();
accinfo.setUserName(userNameField.getString());
accinfo.setPassword(passwordField.getString());
accinfo.setCreditCardNumber(cardNumberField.getString());
accinfo.setCreditCardHolderName(cardHolderNameField.getString());
if(hc.updateAccount(accinfo)==false){
showErrorAlert("发送不成功,请重新发送信息!",AccountInfoUI.this);
}else{
showErrorAlert("发送成功,将返回主屏幕!",AccountInfoUI.this);
}
//关闭progressObserverUI对象
if(progressObserverUI != null)
progressObserverUI = null;
} catch (Exception e) {
showErrorAlert(e.getMessage(), display.getCurrent());
}
}
};
runWithProgress(thread, "正在登陆", false);
}
public void runWithProgress(Thread thread, String title, boolean stoppable) {
progressObserverUI.init(title, stoppable);
display.setCurrent(progressObserverUI);
thread.start();
}
private void showErrorAlert(String message, Displayable d) {
Alert alert = new Alert("错误");
alert.setType(AlertType.ERROR);
alert.setTimeout(Alert.FOREVER);
alert.setString(message);
display.setCurrent(alert, d);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -