Hey guys, the program has to wait until send button in jframe clicked then to get the text and put it in to queue and then send it to server using doInBackground method, also in line 65 i get a compile error which says that ther is nothin to override in super class but if i use java.util.List instead of BlockingQueue it would compile, does any of you guys can help me out here ?
Thanks
public class KKClient extends SwingWorker<BlockingQueue<String>, String> {
KKClientForm Form;
public KKClient(KKClientForm Form) {
this.Form = Form;
}
@Override
public BlockingQueue<String> doInBackground() {
BlockingQueue<String> lines = new ArrayBlockingQueue<String>(10);
Socket kkSocket = null;
PrintWriter out = null;
BufferedReader in = null;
try {
kkSocket = new Socket("localhost", 4444);
out = new PrintWriter(kkSocket.getOutputStream(), true);
in = new BufferedReader(new InputStreamReader(kkSocket.getInputStream()));
String fromServer;
String fromUser;
while ((fromServer = in.readLine()) != null) {
super.publish(new String("< " + fromServer));
if (fromServer.equals("Bye.")) break;
fromUser = lines.poll();
lines.add(new String(fromUser));
super.publish(new String("> " + fromUser));
out.println(fromUser);
}
out.close();
in.close();
kkSocket.close();
} catch (UnknownHostException e) {
lines.add(new String("*** Don't know about host: localhost."));
//System.exit(1);
} catch (IOException e) {
lines.add(new String("*** Couldn't get I/O for the connection to: localhost."));
// System.exit(1);
}
try {
Thread.currentThread().sleep(1000);
} catch (InterruptedException ex) {
;
}
return lines;
}
@Override
protected void process(BlockingQueue<String> lines) {
for (String i : lines) {
Form.TraceBox.append(i+"\r\n");
}
}
@Override
protected void done() {
Form.TraceBox.append("... done!\r\n");
}
}