Search code examples
javamouseevent

Java Convert MouseEvent to ActionEvent


is it possible to convert a MouseEvent to an ActionEvent?


Solution

  • 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());