0

I tried to make it so that,if I pressed the right/left key, the sprite/Mario would face right/left. If I pressed the right key, he would face right. But for some reason, When I pressed the left key, he won't face left.

Source Code: First ,Second

Images

n00begon
  • 3,503
  • 3
  • 29
  • 42
  • For better help sooner, post 1 [SSCCE](http://pscode.org/sscce.html) directly in the question, rather than over 250 lines of uncompilable code in 4 classes at a paste bin site. For the images, feel free to hot-link to some of the images at my [media page](http://pscode.org/media/#image). Alternately, generate them in code as shown in the [Nested Layout Example](http://stackoverflow.com/questions/5621338/about-swing-and-jtable/5630271#5630271). – Andrew Thompson Jul 18 '11 at 03:43
  • If you call `irFrames()` and `ilFrames()` every time you press an arrow key, you are going to be creating a lot of unnecessary `ImageIcon`s. – Jeffrey Jul 18 '11 at 03:44

2 Answers2

2

"To fire keyboard events, a component must have the keyboard focus."—How to Write a Key Listener

trashgod
  • 203,806
  • 29
  • 246
  • 1,045
1

Don't use a KeyListener. Instead use Key Bindings which are more flexible and are used by all Swing components.

camickr
  • 321,443
  • 19
  • 166
  • 288