Don't use a KeyListener. Swing was designed to be used with Key Bindings
.
The probable problem is that the panel doesn't have focus and doesn't respond to the KeyEvents. See Motion Using the Keyboard for more information and a solution using Key Bindings.
Another possible problem is that you don't override the getPreferredSize()
method of your panel to return an appropriate Dimension, so the size is 0 so Swing thinks there is nothing to paint.