Okay I need to make the button esc or any button stop a looping method. I've looked all over but can not find the answer. I know you can exit out of a JFrame with esc. but what about just a regular method? Any help would be great, thanks!
Maybe something like this?
    public class Stop {
    private static boolean loop = true;
    private static int x = 0;
    public static void main(String[] args) throws InterruptedException {
        while (loop == true){
            if (esc not pressed){
                x++;
                System.out.println(x);
            }
            else{
                loop = false;
            }
        }
    }
}