简体   繁体   English

按下按钮的actionPerformed()

[英]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,检查是否按下

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

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