aspose file tools*
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 | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
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: 19544
    
  16

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 - OCEEJBD 6
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: 19544
    
  16

You're welcome.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Help understanding why mouse event seems to be registering twice.
 
Similar Threads
need help with graphics problem
how to make zooming slowly
Popup menu not responding with mouse event
I'm fazed by a nullpointererror I can't get rid of
change color of an oval in a polygon