When do you add the KeyListener? Recommended reading: How to Write a Key Listener (The Java™ Tutorials > Creating a GUI With JFC/Swing > Writing Event Listeners)
Type: Posts; User: KevinWorkman
When do you add the KeyListener? Recommended reading: How to Write a Key Listener (The Java™ Tutorials > Creating a GUI With JFC/Swing > Writing Event Listeners)
Ah, I see. Your keyPressed() method seems to be inside your main() method, which is not allowed. You could have an anonymous inner class, but I don't think that's what you're going for, since you...
You're going to have to supply an SSCCE that demonstrates the error- it could be that the source of your problem is in another piece of code (probably a missing bracket or parenthesis). Boil it down...