• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help understanding why mouse event seems to be registering twice.

 
Felix Chien
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm working on a applet that in part will update the user with the amount of times they have clicked and it seems that the variable I set 'count' is doing: count += 2; instead of what I put down as: count ++; I need help understanding why that is.



Any help is appreciated.
 
Rob Spoor
Sheriff
Pie
Posts: 20611
63
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't call init from your paint method. The paint method is called quite often, in some applets even multiple times per second. That means that you will do all that initialization each and every time. Instead, use the "regular" init method:
Note how I did move the changing of the color of page to the paint methods; that is the one thing from your old init method that you do want to occur during each paint.
 
Felix Chien
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah, Thanks Rob! I was quite confused... That fix worked perfectly =D
 
Rob Spoor
Sheriff
Pie
Posts: 20611
63
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic