Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Mouse Events Not Registering

 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Darin Niard

That worked.

Regards,
Rajesh
 
A "dutch baby" is not a baby. But this tiny ad is baby sized:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic