Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

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

Options
  • 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,079 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