Click to See Complete Forum and Search --> : Add MouseListeners to a canvas/drawing area?{resolved}
System_Error
Jul 22nd, 2005, 09:12 AM
Is there a way to add a mouseListener to a canvas/drawing area? What I want is to draw a horizontal line where ever the mouse is on the drawing surface.
Dillinger4
Jul 22nd, 2005, 01:45 PM
Perhaps have the Canvas implement a MouseMotionListener for the mouse clicking and dragging. mouseDragged(MouseEvent e).
System_Error
Jul 22nd, 2005, 03:15 PM
Perhaps have the Canvas implement a MouseMotionListener for the mouse clicking and dragging. mouseDragged(MouseEvent e).
Ok, the MouseMotionListener i exactly what I was looking for. Now I have a new problem. Everything runs just as it's suppose to, but not like I want. I have a background image behind a graph, and it causes major flicking when redrawn so much. I even put declared and initialized the image outside of the paint method, but draw it in the paint method. Is there some way I can set the background so that it never is redrawin again, but so that the other painting is redrawn?? Maybe in the constructor?
System_Error
Jul 23rd, 2005, 07:53 AM
Alright, I figured this crap out. Thanks for the help dillenger.
Dillinger4
Jul 24th, 2005, 05:56 PM
Just out of curiosity how did you fix the problem? Did you work with a JLayeredPane? :p
System_Error
Jul 24th, 2005, 07:24 PM
Sorry for late reply, our isp is having problems. I tried to override JComponent since it's always transparent, but then none of my stuff in paintComponent() showed up. Since I can't have the flicker, I just went with a solid background in the constructor and that worked fine. There was also readings I found about transparent colors, but those always showed up black for some reason. I thought about painting the image once in the main JApplet class, and have a transparent background on the canvas so it would show through, but that didn't work. If I could find a way to make the color fully transparent and set it to the background in the constructor, then I would be home free. But I just went ahead with a solid color for now.
Thanks.
Dillinger4
Jul 24th, 2005, 08:12 PM
Don't worry about the late reply. I haven't been on that much in the last couple of days. I met an old girlfriend this week on match.com. Ah love :o Anyway. Try working with a JLayerPane and changing the Opacity. Maybe that might do the trick. Good Luck!
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.