[英]for spinner how to detect whether the change is made by button clicked or key pressed?
There are 2 ways to change a spinner's value, either by clicking the up or down button, or by pressing the up or down key. 有两种方法可以更改微调框的值,方法是单击向上或向下按钮,或者按向上或向下键。 If I know spinner's value is changed, how do I know whether it is caused by button clicking or key pressing?
如果我知道微调器的值已更改,如何知道它是由单击按钮还是按键引起的?
Try to get the current event from the event queue. 尝试从事件队列中获取当前事件。
if (EventQueue.getCurrentEvent() instanceof KeyEvent) {
// process key event
} else if (EventQueue.getCurrentEvent() instanceof MouseEvent) {
// process mouse event
}
The method returns an AWTEvent but in most cases it's either mouse or key event. 该方法返回一个AWTEvent,但是在大多数情况下,它是鼠标或键盘事件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.