开发者

Java Convert MouseEvent to ActionEvent

开发者 https://www.devze.com 2023-02-14 14:41 出处:网络
is it possible to conve开发者_开发百科rt a MouseEvent to an ActionEvent?Not without losing some information. The MouseEvent contains information about the mouse location (x, y) and which buttons that

is it possible to conve开发者_开发百科rt a MouseEvent to an ActionEvent?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消