All pastes #369804 Raw Edit

Stuff

public text v1 · immutable
#369804 ·published 2007-02-24 01:51 UTC
rendered paste body
          SwingUtilities.invokeLater(new CWWatcher(in, target, this));

import java.io.BufferedReader;

public class CWWatcher extends Thread implements Runnable {
  BufferedReader in;
  String target;
  CSChatWindow parent;
  
  CWWatcher(BufferedReader in, String target, CSChatWindow parent) {
    this.in = in;
    this.target = parent.getTarget();
    this.parent = parent;
  }
  public void run() {
    int i=0;
    while (true) {
      System.out.println(i);
      try {
        //if (in.ready()) {
        String tmp = in.readLine();
        System.out.println(tmp);
        if (tmp.length()>0) {
          parent.getOutputTextArea().append(target + " said: " +
                                            tmp + "\n");
          in.mark(0);
          in.reset();
          //}
        }
      } catch (java.io.IOException e) {
        System.out.println(e.getMessage());
      } catch (NullPointerException e) {
        System.out.println(e.getMessage());
      }
      try {
        sleep(1000);
      } catch (InterruptedException e) {
        System.out.println(e.getMessage());
      }
      i++;
    }
  }
}



CWWatcher.run() is looping infinitely, as it should do...but it's blocking all updates to the GUI, and I can't even type anything or do anything else.