Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java中mouseListener和mouseMotionListener的区别?_Java_User Interface_Mouse - Fatal编程技术网

Java中mouseListener和mouseMotionListener的区别?

Java中mouseListener和mouseMotionListener的区别?,java,user-interface,mouse,Java,User Interface,Mouse,当鼠标移动到组件上时,mouseMotionListener是否会触发事件,而MouseStener仅在我按下按钮时才会触发 所以如果我只有一个mousePressed事件,那么我就不需要mouseMotionListener了?只有当我有鼠标插入或退出时才可以?是的,你是对的mouseMotionListener用于在鼠标移动到“热点”上时执行操作 我们可以找到很好的例子 处理mousePressed事件时,您只需要mousePressed事件,除非您想在鼠标悬停时添加更多要执行的事件。它们侦

当鼠标移动到组件上时,mouseMotionListener是否会触发事件,而MouseStener仅在我按下按钮时才会触发


所以如果我只有一个mousePressed事件,那么我就不需要mouseMotionListener了?只有当我有鼠标插入或退出时才可以?

是的,你是对的
mouseMotionListener
用于在鼠标移动到“热点”上时执行操作

我们可以找到很好的例子


处理
mousePressed
事件时,您只需要
mousePressed
事件,除非您想在鼠标悬停时添加更多要执行的事件。

它们侦听不同的事件:

根据您所关注的事件添加侦听器

mouseClicked(MouseEvent event)   // Called just after the user clicks the listened-to component.
mouseEntered(MouseEvent event)   // Called just after the cursor enters the bounds of the listened-to component.
mouseExited(MouseEvent event)    // Called just after the cursor exits the bounds of the listened-to component.
mousePressed(MouseEvent event)   // Called just after the user presses a mouse button while the cursor is over the listened-to component.
mouseReleased(MouseEvent event)  // Called just after the user releases a mouse button after a mouse press over the listened-to component
mouseDragged(MouseEvent event)   // Called in response to the user moving the mouse while holding a mouse button down. This event is fired by the component that fired the most recent mouse-pressed event, even if the cursor is no longer over that component.
mouseMoved(MouseEvent event)     // Called in response to the user moving the mouse with no mouse buttons pressed. This event is fired by the component that's currently under the cursor.