KeyboardThread.java 590 Bytes
Newer Older
Michele Fiori's avatar
Michele Fiori committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
package chat;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class KeyboardThread extends Thread {
    private Queue q;

    public KeyboardThread(Queue q) {
        this.q = q;
    }

    public void run() {
        BufferedReader inFromUser =
                new BufferedReader(new InputStreamReader(System.in));

        while(true) {
            try {
                q.put(inFromUser.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}