📄 c0e13405ed9a001b1a36b107245978e8
字号:
package bankbillClent;import javax.microedition.lcdui.*;import javax.microedition.midlet.*;import com.chapter16.shared.BillInfo;public class SignOnUI extends Form implements CommandListener { private TextField userNameField; private TextField passwordField; private Command signOnCommand; private Command backCommand; private MIDlet midlet; private Display display; private Displayable parent; private ProgressObserverUI progressObserverUI; public SignOnUI(MIDlet midlet,Displayable parent) { super("登陆"); userNameField = new TextField("用户名:", null, 12, TextField.ANY); passwordField = new TextField("密码:", null, 20, TextField.PASSWORD); signOnCommand = 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); addCommand(signOnCommand); addCommand(backCommand); setCommandListener(this); } public void init() { userNameField.setString(null); passwordField.setString(null); } public void commandAction(Command command, Displayable displayable) { if(command == signOnCommand){ signOn(userNameField.getString(), passwordField.getString()); } if(command == backCommand){ display.setCurrent(parent); } } public void signOn(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/TEst/BankBillServlet"; HTTPCommunication hc = new HTTPCommunication(url,progressObserverUI); //显示帐单情况 if(hc.login(userName,password) == true){ BillInfo[] binfo = hc.getBillData(); bbui = new BankBillListUI(midlet,parent,binfo); display.setCurrent(bbui); }else{ showErrorAlert("登陆不成功,请重新输入用户名和密码!",SignOnUI.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 + -