简体   繁体   English

Java将MouseEvent转换为ActionEvent

[英]Java Convert MouseEvent to ActionEvent

是否可以将MouseEvent转换为ActionEvent?

Not without losing some information. 并非没有失去一些信息。 The MouseEvent contains information about the mouse location ( x, y ) and which buttons that are pressed (if any). MouseEvent包含有关鼠标位置( x, y )和按下的按钮(如果有)的信息。


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 . 它处理MouseEvent并创建(发送) 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"). 此动作事件的触发器可能是鼠标事件(“当鼠标指针位于由AWT按钮小部件定义的矩形时按下并释放左按钮”)或键盘事件(“空格键已被按下并释放而重点是在AWT Button小部件“)。

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. 实际上,您必须听动鼠标事件并向动作听众发起新的动作事件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM