Piccolo esempio:
codice:
import java.io.*;
public class Main {
public static void main(String[] args) throws Exception {
Tastiera t = new Tastiera();
t.start();
int i = 0;
while (i < 1000) {
i++;
System.out.println(i);
Thread.sleep(500);
}
}
}
import java.io.*;
public class Tastiera extends Thread {
private boolean attivo;
private BufferedReader br;
public Tastiera() {
attivo = true;
}
public void run() {
try {
String testo;
br = new BufferedReader( new InputStreamReader( System.in ) );
while( attivo ) {
testo = br.readLine();
System.out.println("Hai digitato: " + testo);
}
} catch (Exception e) {}
}
public void disattiva() { attivo = false; }
}
Ciao.