可以移动图标吗?
在Java中,是否可以使用paintIcon将图标放入画布中,然后使用键盘事件移动该图标,就像游戏角色一样?
In Java, is it possible to use paintIcon to put an icon into a canvas, and then move that icon around using keyboard events like you would a game character?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
一旦你在画布上画了一些东西,它就会留在那里,而那个位置下面的东西就会丢失。要“移动”图标,您需要重新绘制画布(或至少重新绘制图标原来所在位置的画布)并在新位置绘制图标。
Once you paint something on the canvas, it stays there, and what was there beneath that location is lost. To "move" the icon, you need to repaint the canvas (or at least what was originally at the location of the icon) and draw the icon at its new position.
通过注册按键侦听器,这可以更好地与小程序配合使用。
并重写paint方法
This would work better with an applet by registering keylisteners.
and overridding the paint method