 <p>If you search here for similar questions, the answer almost always is:</p> <ul> <li>KeyListeners only work if the listened-to component has the focus.</li> <li>And the component must be focusable.</li> </ul> <p>But there's more...</p> <ul> <li>You should not draw in a JFrame</li> <li>Instead draw in a JPanel or JComponent</li> <li>And extend the paintComponent method</li> <li>And call the super method</li> <li>and search here for similar questions for more on this</li> <li>and check the tutorials on drawing ..</li> <li>Next you'll want to use key bindings instead of KeyListeners. Again, this has been well discussed on this site, but KeyListeners are very low-level listeners. You're almost always better off using higher-level constructs such as Key Bindings. Bindings are the way that Swing components listen for key strokes. They also are much more flexible when it comes to component focus.</li> </ul>