Java animation, with key listener

霸气de小男生 提交于 2019-12-13 04:44:45

问题


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


回答1:


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




回答2:


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



来源:https://stackoverflow.com/questions/6728389/java-animation-with-key-listener

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!