2

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?

mre
  • 43,520
  • 33
  • 120
  • 170
BloonsTowerDefence
  • 1,184
  • 2
  • 18
  • 43

2 Answers2

4

You will need to use a MouseListener and override the mousePressed() method. 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

Community
  • 1
  • 1
htz
  • 1,037
  • 1
  • 13
  • 37
  • I agree with you. You override mousePressed() and you manage your process at the end via mouseReleased(), when you release the mouse button. Take note of windows super button, if you click it while zooming you'll lose focus and your code will procede without control. Adding a simple condition via a keylistener do the job. – neo Feb 26 '13 at 16:20
2
mKorbel
  • 109,525
  • 20
  • 134
  • 319