Canvas and InputMap

时光毁灭记忆、已成空白 提交于 2019-12-23 15:43:09

问题


I'm building a 2d game in Java and I decided to use Canvas on which I would display the images relevant to the current frame. I'm using Canvas because I've heard it is more efficient in terms of time than JPanel. Is it true?

Also, I would like to add some input to the game through key bindings since key listeners could cause focus issues and are lower level construct: keylistener not working after clicking button (see answer). Is there a way to use key bindings with a Canvas? Or I would simply use KeyListener.


回答1:


  • you can't add KeyBindings to awt.Canvas, there isn't method implemented in API

  • you can to add only KeyListener

  • change your decision and to use JPanel/JComponent



来源:https://stackoverflow.com/questions/19211932/canvas-and-inputmap

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