[英]actionPerformed() for button hold down
Right now I have: 现在我有:
panel.getZoomButton().addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ACtionEvent e)
{
zoom();
}
}
This is called every time the zoom button is pressed. 每次按下变焦按钮时都会调用此方法。 How can I change it so that
zoom()
will be continuously called if the zoom button is being held down? 我如何更改它,以便在按住变焦按钮的情况下连续调用
zoom()
?
You will need to use a MouseListener
and override the mousePressed()
method. 您将需要使用
MouseListener
并重写mousePressed()
方法。 There you can use a Timer or something similar to measure the time, the button has been pressed, in order to calculate your zoom. 在这里,您可以使用计时器或类似的工具来测量时间(已按下按钮),以便计算缩放比例。
Perhaps this question helps you with that: Java MouseEvent, check if pressed down 也许这个问题可以帮助您: Java MouseEvent,检查是否按下
use Swing Action (most scallable abstraction) instead of ActionListener , there you can to set isEnabled , to switch to false value
until all events are done 使用Swing Action (最可调用的抽象)代替ActionListener ,在那里您可以设置isEnabled ,以切换为
false value
直到完成所有事件
or add Swing Timer for reset Boolean
to true value
或添加Swing Timer以将
Boolean
true value
重置为true value
there is possible to setMultiClickThreshhold(long threshhold) , but is aplicable only for MouseEvents, this methods doesn't react to KeyBindings
( ENTER
and TAB
) firing from Keyboard 可以设置setMultiClickThreshhold(long threshhold) ,但是仅适用于MouseEvents,此方法对从Keyboard触发的
KeyBindings
( ENTER
和TAB
)不起作用
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.