Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Mouse Events Not Registering  RSS feed

 
Greedy thomas
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello There

I'm trying to draw lines on a drawing panel using the mouse to press, drag and release to draw a line. I also need to add functionality to allow the user to change the color of the line. I've just started on this and somehow I cannot get the mouse events to register.

I've enclosed the code below. Could someone please tell me what I'm missing.

Please help me figure out my problem. Why are the mouse clicks not being registered.

Thanks in advance,
Rajesh.

 
Steve JK
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I dont have the time to properly test this and give you a definite answer right now,

But I suspect it is because you havent actually assigned the Mouse Listener to the Drawing Panel.

Try something like this: drawPanel.addMouseListener(new MouseAdapter....

Assigning the Mouse Listener to the drawing panel should then detect mouse events that occur on the drawing panel.

Sorry havent time to produce complete code for you, but try the above and let me know if it works or not.?

Cheers,
Steve
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving this to the Swing / JFC / AWT forum...
 
Greedy thomas
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Steve for the suggestion.

I did try what you had suggested but I'm still having the same problem. It's still not picking up the mouse events.

Any suggestions, anyone.

Regards,
Rajesh
 
Darin Niard
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's because your methods are named MousePressed() and
MouseDragged() instead of mousePressed() and mouseDragged()

[ June 23, 2004: Message edited by: Darin Niard ]
[ June 23, 2004: Message edited by: Gregg Bolinger ]
 
Greedy thomas
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Darin Niard

That worked.

Regards,
Rajesh
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!