Разработка мобильных приложений. Соколова В.В. - 120 стр.

UptoLike

Составители: 

120
public class MidletFormHandler extends MIDlet {
public static final String URL =
"http://localhost:8080/sample/";
public void startApp() {
String html = null;
try {
html = getHtml(URL);
FormData form = convertFormData(html);
form.composeInterface(Display.getDisplay(this));
}
catch (IOException ex) {
Alert alert = new Alert(
"I/O Error", ex.getMessage(), null,
AlertType.ERROR);
Display.getDisplay(this).setCurrent(alert);
}
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
private String getHtml(String url) throws IOException {
HttpConnection connection = null;
DataInputStream dis = null;
byte[] data = null;
try {
connection = (HttpConnection) Connec-
tor.open(url);
int length = (int) connection.getLength();
data = new byte[length];
dis = new DataInput-
Stream(connection.openInputStream());
dis.readFully(data);
}
finally {
if (dis != null)
dis.close();
if (connection != null)
connection.close();
}
return new String(data);
}
private FormData convertFormData(String html) {
// We miss the process of html parsing here. Just
create the FormData
// object by hand
Vector inputs = new Vector();