Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Java - Mouse click appears to be incrementing more than once..

  • 24-04-2009 11:32AM
    #1
    Closed Accounts Posts: 20,759 ✭✭✭✭


    I have a counter to keep track of a few arrays, everything works fine - but when I increment the counter via a button listener on click, it appears to increment it more than once. Unsure why this is.. Does anybody have an idea as to why?

    Code: http://www.pastebin.ca/1401752

    Check out from line 339 onwards..

    Thanks in advance! :)

    John.


Comments

  • Moderators, Science, Health & Environment Moderators Posts: 10,093 Mod ✭✭✭✭marco_polo


    dlofnep wrote: »
    I have a counter to keep track of a few arrays, everything works fine - but when I increment the counter via a button listener on click, it appears to increment it more than once. Unsure why this is.. Does anybody have an idea as to why?

    Code: http://www.pastebin.ca/1401752

    Check out from line 339 onwards..

    Thanks in advance! :)

    John.

    In the actionListener you call the start() method, which adds an action listener to the next and previous buttons. So it looks like every time you click the button you are adding a new listener to the button.

    Oh and because of the way you have written the ActionListner you need only create one instance and share it amongst all the buttons.


  • Closed Accounts Posts: 20,759 ✭✭✭✭dlofnep


    Ah yeah, got it.. Forgot to remove that out of the start() method. Works now ;)


Advertisement