Java Convert MouseEvent to ActionEvent

Can I convert a MouseEvent to an ActionEvent?

+7
source share
2 answers

Without losing information. MouseEvent contains information about the location of the mouse ( x, y ) and the buttons that are pressed (if any).


I would do the following conversion:

 MouseEvent me = ...; ActionEvent ae = new ActionEvent(me.getSource(), me.getID(), me.paramString()); 
+7
source

Of course, this is what the button does (in my opinion). It processes a MouseEvent and creates (dispatches) an ActionEvent .

Event events are semantic events - as a signal that a certain button (widget!) Has been pressed. The trigger for this action can be a mouse event ("the left button was pressed and released when the mouse cursor was in the rectangle defined by the AWT button widgets") or a keyboard event ("Space was pressed and released while the main focus was on the AWT widget" Button ").

I think you are not looking at technical conversion. In practice, you will have to listen to mouse events and trigger new actions for your action listeners.

+3
source

All Articles