Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

MouseListener and coordinate display  RSS feed

 
nick woodward
Ranch Hand
Posts: 370
11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was just wondering if anyone could help me check this code please.

It's supposed to display the coordinates of the mouse on a JLabel when clicked, but it doesn't register if the mouse is moved even slightly while clicking. I've written vaguely similar code (but storing the dimensions locally and then calling repaint on the JFrame) with no such problem. Is there any reason why setting the text of a label should behave differently, or have I made a mistake somewhere?




am happy to paste the other code too if needed.

thanks,

Nick
 
Piet Souris
Rancher
Posts: 1783
55
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Nick,

you are using 'mouseClicked'. That means you only get to hear
of a mouse click when the mouse button is released. Now,
if there is some distance between the location when the mouse
button was pressed and the location where it is released, then
mouseClicked is not invoked at all.

So, if you want some accuracy, use the methods 'mousePressed'
and 'mouseReleased'.
 
nick woodward
Ranch Hand
Posts: 370
11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Piet Souris wrote:hi Nick,

you are using 'mouseClicked'. That means you only get to hear
of a mouse click when the mouse button is released. Now,
if there is some distance between the location when the mouse
button was pressed and the location where it is released, then
mouseClicked is not invoked at all.

So, if you want some accuracy, use the methods 'mousePressed'
and 'mouseReleased'.


thanks a lot! - i had completely missed that i'd used mousePressed in the other code!

Nick
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!