puoi fare un thread che attende un carattere da tastieracodice:class KeyListener extends Thread { public void run() { java.io.InputStream IS = System.in; try { int ch = ' '; while (ch == 'Q') { ch = IS.read(); } // codice per terminare il ciclo } catch (java.io.IOException ioex) { } } }