I am trying to create a program where a image is on the screen and if the variable keycode is equal to the key VK_ESCAPE it will remove the image from the screen using the method validate. How can I focus the keylistener so I can run the if statement and validate the image. I have the correct libraries imported and I am getting no errors?!
public void keyPressed(KeyEvent e){
    int keycode = e.getKeyCode();
    if(keycode == KeyEvent.VK_ESCAPE){
     scroll = new ImageIcon("").getImage();
     validate();
     e.consume();
    }
}