This week's giveaways are in the MongoDB and Jobs Discussion forums.
We're giving away four copies of Mongo DB Applied Patterns and 4 resume reviews from Five Year Itch and have the authors/reps on-line!
See this thread and this one for details.
The moose likes Swing / AWT / SWT and the fly likes Help understanding why mouse event seems to be registering twice. Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of Mongo DB Applied Patterns this week in the MongoDB forum
or a resume review from Five Year Itch in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Reply Bookmark "Help understanding why mouse event seems to be registering twice." Watch "Help understanding why mouse event seems to be registering twice." New topic
Author

Help understanding why mouse event seems to be registering twice.

Felix Chien
Greenhorn

Joined: Sep 25, 2011
Posts: 4
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

Joined: Oct 27, 2005
Posts: 19214

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.


SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
Felix Chien
Greenhorn

Joined: Sep 25, 2011
Posts: 4
Ah, Thanks Rob! I was quite confused... That fix worked perfectly =D
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19214

You're welcome.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Help understanding why mouse event seems to be registering twice.
 
Similar Threads
Popup menu not responding with mouse event
change color of an oval in a polygon
need help with graphics problem
I'm fazed by a nullpointererror I can't get rid of
how to make zooming slowly