Difference between Mouse Listener and Action Listener?

前端 未结 3 1302
无人共我
无人共我 2021-02-10 02:05

Whats the difference? When would you use a mouse listener? or a action listener? Please and Thank You!

3条回答
  •  故里飘歌
    2021-02-10 02:53

    The first difference is that A MouseEvent is a true system event, whereas an ActionEvent is a synthesized event... It is triggered by a system event.

    MouseListener (and MouseMotionLister, MouseWheelListener) are useful when (a) you are interested in the event details (ie x/y click spot) or when the component you are using doesn't support ActionListeners

    Actions are good when you have a task that can executed without external event details (like exiting the program) and that you'd like to be able to access either in more than one component, or to set off / start with either the keyboard or the mouse

提交回复
热议问题