I am trying to get my program to listen for keyboard inputs, but I can't get it to work properly. My code is
import java.awt.event.KeyEvent;
public class test {
public static void main(String[] args){
KeyListener keyboard = new KeyListener() {
@Override
public void keyPressed(KeyEvent event) {
System.out.println("yes");
}
@Override
public void keyReleased(KeyEvent event) {
}
@Override
public void keyTyped(KeyEvent event) {
}
};
//this is so the program doesn't end
for (int i = 1; i > 0; i++) {
System.out.print("");
}
}
}```
The program runs fine, but the listener doesn't work. Do you know why?
Thanks!