is it possible to convert a MouseEvent to an ActionEvent?
public class MouseEvent extends InputEvent. An event which indicates that a mouse action occurred in a component. A mouse action is considered to occur in a particular component if and only if the mouse cursor is over the unobscured part of the component's bounds when the action happens.
A MouseEvent object is also passed to every MouseMotionListener or MouseMotionAdapter object which is registered to receive mouse motion events using the component's addMouseMotionListener method.
The MouseEvent class inherits many useful methods from InputEvent and a couple handy methods from the ComponentEvent and AWTEvent classes. Returns the event type, which defines the particular action. For example, the MouseEvent id reflects the state of the mouse buttons for every mouse event.
To register a handler object, you invoke the source object's registration method; for example, button. setOnAction (handler) for registering a handler for a button action event. To implement a handler interface, you implement the method defined in the handler interface.
Not without losing some information. The MouseEvent
contains information about the mouse location (x, y
) and which buttons that are pressed (if any).
I would do the conversion like this:
MouseEvent me = ...;
ActionEvent ae = new ActionEvent(me.getSource(), me.getID(), me.paramString());
Sure, that's what a Button does (to my understanding). It processes a MouseEvent
and creates (sends) an ActionEvent
.
Action events are semantic events - like a signal, that a certain button (widget!) has been "pressed". The trigger for this action event may have been a mouse event ("left button has been pressed and released while the mouse pointer was in the rectangle defined by a AWT Button widget") or a keyboard event ("Space bar has been pressed and released while the focus was at AWT Button widget").
I guess you're not looking at a technical conversion. Practiacally, you'll have to listen to mouse events and fire new action events to your action listeners.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With