这是我的示例代码...我面临的问题是我的 swingWorker 扩展类仅向我显示 doInBackground() 作为覆盖方法。我也想使用 done() 和 process() 方法,但是我的类没有显示它@overided 也没有调用 done/process 方法,因为我知道它是无限循环,但是为什么不是在发布()时调用流程方法吗?
public class getChatSwingWorkerThread extends SwingWorker<String , String> {
private final JTextArea chat_text_area;
private PostDataConnection post = null;
private BasicUserInterface chatWindow = null;
public getChatSwingWorkerThread(JTextArea text_area){
chatWindow = new BasicUserInterface();
this.chat_text_area = text_area;
post = new PostDataConnection();
}
@Override
protected String doInBackground() throws Exception {
String returnData = "";
while(true){
returnData = post.getAvailableChat();
if(!returnData.equals("")){
publish(returnData);
}
}
}
protected void process(String returnData) {
chat_text_area.append(returnData);
}
public void done(String returnData) throws InterruptedException, ExecutionException{
chat_text_area.append(get());
}