简体   繁体   English

JAVA用鼠标单击,用键盘移动

[英]JAVA click with mouse, move with keyboard

I wanted to select an object inside the JFrame and move it with the keyboard arrow keys. 我想在JFrame中选择一个对象,然后使用键盘上的箭头键移动它。 I did the keyboard thing, whenever I pressed the arrow keys it moves accordingly to the direction. 我做了键盘操作,每当我按箭头键时,它就会相应地移动。 What I want is to move multiple objects. 我想要的是移动多个对象。 I tried to put an multiple objects and they did moved at the same time xD 我试图放置多个对象,但它们确实同时移动了xD

tldr; tldr; is there a way where you can click on just one object using the mouse and control it with keyboard arrow keys? 有没有一种方法可以使您只用鼠标单击一个对象并用键盘上的箭头键控制它?

Eventhough question not clear enough, moving single or multiple objects is not a problem. 尽管问题还不够清楚,但移动单个或多个对象也不是问题。 You need to use KeyEvent Listener for the object you want to listen and move the components based on KeyEvent. 您需要为要侦听的对象使用KeyEvent Listener,并基于KeyEvent移动组件。

Here some reference: http://download.oracle.com/javase/tutorial/uiswing/events/keylistener.html 这里是一些参考: http : //download.oracle.com/javase/tutorial/uiswing/events/keylistener.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM