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");
	}


}

The compile error is due to the fact that BlockingQueue does not implement the List interface anywhere in it's hierarchy, which is what the SwingWorker requires in the process(List) method. You really only need to specify the type for the List parameter when you override it, because it is called internally by the mechanics of the publish() method.

Since you are publishing String objects, declare your process() method like this

@Override
protected void process(List<String> lines) {
    for (String i : lines) {
        Form.TraceBox.append(i+"\r\n");
    }
}

You just simply made my day bro, Thank you so much.

This question has already been answered. Start a new discussion instead.