mouseMotionListener는 마우스가 컴포넌트 위에서 움직이면 이벤트를 트리거 할 것인가? 반면 mouseListener는 버튼을 눌러야 만 트리거 되는가?Java에서 mouseListener와 mouseMotionListener의 차이점은 무엇입니까?
그래서 mousePressed 이벤트 만있는 경우 mouseMotionListener가 필요하지 않습니까? 나는 mouseEntered 또는 mouseExited가있는 경우에만?
mouseMotionListener는 마우스가 컴포넌트 위에서 움직이면 이벤트를 트리거 할 것인가? 반면 mouseListener는 버튼을 눌러야 만 트리거 되는가?Java에서 mouseListener와 mouseMotionListener의 차이점은 무엇입니까?
그래서 mousePressed 이벤트 만있는 경우 mouseMotionListener가 필요하지 않습니까? 나는 mouseEntered 또는 mouseExited가있는 경우에만?
네, 맞습니다. mouseMotionListener
는 위에 마우스 이동은 "핫스팟"때 작업을 수행하는 데 사용됩니다
좋은 예는 당신이 동안을 수행 할 수있는 많은 이벤트를 추가하고 싶어하지 않는 here
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.
가 필요하시면 이벤트에 따라 청취자를 추가합니다.