Hello,
I want to try and run a thread that starts running on start and quits after pressing a key.
I cant seem to detect keypresses. can anyone help me out with this?
Thanks in advance..
i cant seem to add code:
Post denied. New posts are limited by number of URLs it may contain and checked if it doesn't contain forbidden words.
its just a code snippit without links or anything...
this is a small part... but how do i add a keyListener in here that listends to a random key?
The class implements KeyListener and the overrided method "keyPressed" sets the isRunning boolean to false... but the keyPressed method is never executed.
public static void main(String[] args) { Thread thread = new Thread() { public void run() { while(isRunning){ System.out.println("running"); try { sleep(1000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } }; thread.start(); }