📄 httpget.java
字号:
package com.j2medev.ch6.get;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class HttpGET extends MIDlet implements CommandListener{
private Display display = null;
private Form mainForm = null;
private HttpThread http = null;
private TextField user = new TextField("用户名:", "", 20, TextField.ANY);
private TextField password = new TextField("密 码:", "",20, TextField.PASSWORD);
private Command loginCommand = new Command("登录",Command.OK, 1);
private Command exitCommand = new Command("退出",Command.EXIT,2);
public void startApp() {
if(display == null){
display = Display.getDisplay(this);
mainForm = new Form("登录界面");
mainForm.append(user);
mainForm.append(password);
mainForm.addCommand(loginCommand);
mainForm.addCommand(exitCommand);
mainForm.setCommandListener(this);
http = new HttpThread(this);
new Thread(http).start();
display.setCurrent(mainForm);
}else{
display.setCurrent(mainForm);
}
}
//根据服务器端返回的int类型数据判断是否登录成功
public void displayResult(int result){
if(result == 100){
Form success = new Form("登录成功");
success.append("恭喜您,成功登录了服务器!");
display.setCurrent(success);
}else{
Alert alert = new Alert("错误");
alert.setString("用户密码错误!");
alert.setType(AlertType.ERROR);
alert.setTimeout(2000);
display.setCurrent(alert, mainForm);
}
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
public void exit(){
destroyApp(false);
notifyDestroyed();
}
public void commandAction(Command cmd,Displayable displayable){
if(cmd == loginCommand){
String userName = user.getString();
String pass = password.getString();
String urlData = "username="+userName+"&password="+pass;
System.out.println(urlData);
http.setURLData(urlData);
synchronized(this){
notify();
}
}else if(cmd == exitCommand){
exit();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -