📄 cookiemidlet.java
字号:
/*
* CookieMIDlet.java
*
* Created on 2006年6月20日, 下午9:45
*/
package com.j2medev.chapter4;
import java.io.IOException;
import java.io.OutputStream;
import javax.microedition.io.Connector;
import javax.microedition.io.HttpConnection;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
/**
*
* @author ming
* @version
*/
public class CookieMIDlet extends MIDlet implements CommandListener {
private Display display = null;
public static final Command exitCommand = new Command("Exit",Command.EXIT,1);
public static final Command okCommand = new Command("Ok",Command.OK,1);
public void startApp() {
display = Display.getDisplay(this);
Form form = new Form("cookie");
form.append("click to send request to server");
form.addCommand(exitCommand);
form.addCommand(okCommand);
form.setCommandListener(this);
display.setCurrent(form);
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
public void commandAction(Command command, Displayable displayable) {
if(command == exitCommand){
destroyApp(false);
notifyDestroyed();
}else if(command == okCommand){
new Thread(){
public void run(){
try{
String url = "http://localhost:8080/myapp/myservlet?hello=world";
HttpConnection conn = (HttpConnection)Connector.open(url);
conn.setRequestProperty("platform","k700");
OutputStream os = conn.openOutputStream();
os.close();
conn.close();
Alert alert = new Alert("info");
alert.setTimeout(1500);
alert.setString("send to server successfully");
display.setCurrent(alert);
}catch(IOException ex){
ex.printStackTrace();
}
}
}.start();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -