?? httpexamplemid.java
字號:
import java.io.DataInputStream;
import java.io.IOException;
import javax.microedition.io.Connector;
import javax.microedition.io.ContentConnection;
import javax.microedition.io.HttpConnection;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.TextBox;
import javax.microedition.lcdui.Ticker;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
public class HttpExampleMID extends MIDlet implements CommandListener {
Command exit=null;
TextBox tb=null;
public String str=null;
Ticker t=null;
public HttpExampleMID()
{
exit=new Command("退出",7,1);
tb=new TextBox("信息","",200,0);
str="http://www.163.com";
t=new Ticker("哈哈哈哈");
tb.addCommand(exit);
tb.setCommandListener(this);
}
protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
}
protected void pauseApp() {
}
public void startApp() throws MIDletStateChangeException{
HttpConnection httpconnection=null;
StringBuffer stringBuffer=new StringBuffer();
try {
httpconnection=(HttpConnection)Connector.open(str);
// this.platformRequest("http://www.163.com");
// getViaContentConnection("http://www.163.com");
stringBuffer.append("Host主機名:"+httpconnection.getHost() + "\n" //////獲得此 URL 的主機名
+"Port端口號:"+httpconnection.getPort() + "\n" ///// 獲得此 URL 的端口號
+"Date頭字段:"+httpconnection.getDate() + "\n" ///// 返回 date 頭字段的值
+"Encoding字符編碼:"+httpconnection.getEncoding() + "\n" /////返回此流使用的字符編碼的名稱
+"Protocol協議名稱:"+httpconnection.getProtocol() + "\n" /////獲得此 URL 的協議名稱
+"File文件名:"+httpconnection.getFile() + "\n" /////獲得此 URL 的文件名
+"Tpye控件類型:"+httpconnection.getType() + "\n" /////獲得控件的類型
+"URL字段:"+httpconnection.getURL() + "\n" /////返回此 URL 字段的值
+"Ref錨點:"+httpconnection.getRef() + "\n" /////獲得此 getQuery URL 的錨點(也稱為“引用”)
+"Query查詢部分:"+httpconnection.getQuery() + "\n" ///// 獲得此 URL 的查詢部分。
);
// stringBuffer.append("Host: " + httpconnection.getHost() + "\n");
// stringBuffer.append("Port: " + httpconnection.getPort() + "\n");
// stringBuffer.append("Date: " + httpconnection.getDate() + "\n");
// stringBuffer.append("Encoding: " + httpconnection.getEncoding() + "\n");
// stringBuffer.append("Protocol: " + httpconnection.getProtocol() + "\n");
// stringBuffer.append("File: " + httpconnection.getFile() + "\n");
// stringBuffer.append("Type: " + httpconnection.getType() + "\n");
} catch (IOException e) {
e.printStackTrace();
}
try {
httpconnection.close();
} catch (IOException e) {
e.printStackTrace();
}
tb.setString(stringBuffer.toString());
tb.setTicker(t);
Display.getDisplay(this).setCurrent(tb);
}
void getViaContentConnection(String url) throws IOException {
ContentConnection c = null;
DataInputStream dis = null;
try {
c = (ContentConnection)Connector.open(url);
int len = (int)c.getLength();
dis = c.openDataInputStream();
if (len > 0) {
byte[] data = new byte[len];
dis.readFully(data);
} else {
// int ch;
// while ((ch = dis.read()) != -1) {
//
// }
}
} finally {
if (dis != null)
dis.close();
if (c != null)
c.close();
}
}
public void commandAction(Command c, Displayable d) {
if(c==exit)
notifyDestroyed();
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -