I've just had my first dab in Java 2d graphics and have created a quick and rather crude program which draws a line between two points. The problem I am experiencing is that a lot of the mouse clicks just do not register on the JPanel. Any idea how to fix this? My code is below:
Ulf Dittmer wrote:Seems to work fine for me. What, exactly, are you experiencing?
Sometimes the mouse clicks just do not register. I added System.out.println(clickCounter); in the code to detect when they are registered and sometimes I am definitely clicking the panel but it just doesn't register. There's no other way for we to describe what's happening.
Rob Spoor wrote:And you forgot to call super.paintComponent(g) in your paintComponent method.
Why may I ask. - I haven't read that far ahead so maybe it's something that will come up but if you could explain it now, that would be great
super.paintComponent(g) makes sure the panel is drawn with a clean slate - all custom drawings will be removed. Currently, if the values in your locations array would change the repainting would only add the new locations, not remove the old ones.
Rob Spoor wrote:And you forgot to call super.paintComponent(g) in your paintComponent method.
Why may I ask. - I haven't read that far ahead so maybe it's something that will come up but if you could explain it now, that would be great
super.paintComponent(g) makes sure the panel is drawn with a clean slate - all custom drawings will be removed. Currently, if the values in your locations array would change the repainting would only add the new locations, not remove the old ones.
Hmm, that doesn't seem true. If you run the program you will see, it adds a new line whilst simultaneously removing the old line?
Cob is sand, clay and sometimes straw. This tiny ad is made of cob: