📄 viewform.java
字号:
package com;
/*
* ViewForm.java
*
* Created on 2007年4月13日, 下午2:14
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
/**
*
* @author chenzs
*/
import java.io.*;
import javax.microedition.io.*;
import javax.microedition.lcdui.*;
public class ViewForm extends DynamicForm{
String httpURL;
/** Creates a new instance of ViewForm */
public ViewForm(String title, String url) {
super(title);
httpURL = url;
start();
(new HttpConnThread()).start();
}
public void getHttpConnection(){
HttpConnection httpConn = null;
InputStream is = null;
byte[] databuf;
try{
httpConn = (HttpConnection)Connector.open(httpURL);
// setRequestHeaders(httpConn);
int responseCode = httpConn.getResponseCode();
//append msg
StringItem msgResp = new StringItem("Response Code", ":"+responseCode);
append(msgResp);
//get response data
is = httpConn.openInputStream();
DataInputStream dis = new DataInputStream(is);
int length = dis.available();
databuf = new byte[length];
dis.read(databuf);
//stop thread
stop();
label.setLabel("Finished !");
append(new String(databuf));
dis.close();
is.close();
httpConn.close();
}
catch(IOException e){
append(e.toString());
}
}
/**
* Add request properties for the configuration, profiles,
* and locale of this system.
* @param c current HttpConnection to apply request headers
*/
void setRequestHeaders(HttpConnection c) throws IOException {
// String conf = System.getProperty("microedition.configuration");
// String prof = System.getProperty("microedition.profiles");
// int space = prof.indexOf(' ');
// if (space != -1) {
// prof = prof.substring(0, space -1);
// }
String locale = System.getProperty("microedition.locale");
// String ua = "Profile/" + prof +
// " Configuration/" + conf;
c.setRequestProperty("User-Agent", "Mozilla/4.0");
if (locale != null) {
c.setRequestProperty("Content-Language", locale);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -