I have this code:
import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
imp
KeyListener will only fire events if the component it is registered is focusable and has focus.
JApplet has a JRootPane which adds a JLayeredPane and content pane (amongst other things) ontop of the applet, which may mean that key listener may never be capable of begin notified of events (as other elements are blocking it).
Instead, use Key Bindings