Java Reference
In-Depth Information
notifyDestroyed();
}
});
frame.pack();
}
void configure() {
disconnect();
new ConfigDialog().show();
}
void connect() {
disconnect();
if (transfer (null)) {
timer = new Timer();
timer.schedule (new RefreshTask(), 0, 4000);
}
}
void disconnect() {
if (timer != null) {
timer.cancel();
timer = null;
}
}
/** implementation of runnable */
public void run() {
transfer (null);
}
boolean transfer (String submit) { // if null, just read
try {
HttpConnection connection = (HttpConnection)
Connector.open(host + "/?start="+count, submit !=
null? Connector.READ_WRITE : Connector.READ);
Writer writer = null;
if (submit != null) {
connection.setRequestMethod (HttpConnection.POST);
writer = new OutputStreamWriter
(((StreamConnection)connection).openOutputStream());
writer.write ("nick="+nick + "\r\n");
writer.write ("text="+submit+"\r\n");
writer.close();
}
Reader reader = new InputStreamReader
(((StreamConnection) connection).openInputStream());
count = Integer.parseInt (readLine (reader));
while (true) {
String s = readLine (reader);
if (s == null || s.length() == 0) break;
addLine (s);
}
reader.close();
connection.close();
return true;
}
catch (Exception e) {
addLine (e.toString());
disconnect();
Search WWH ::




Custom Search