Whats the difference? When would you use a mouse listener? or a action listener? Please and Thank You!
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
An ActionListener is used to handle the logical click of a button. A click happens:
A MouseListener only handles low-level mouse events.
ActionListener Doc's
MouseListener Doc's
From the docs you can see that the usage of this interfaces is completly different. While you can use the
MouseListener
only in combination with gui elements, theActionListener
is also used when there is no gui, for example in combination with a timer.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
Action
s 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