|
-
Jul 22nd, 2005, 09:12 AM
#1
Thread Starter
Frenzied Member
Add MouseListeners to a canvas/drawing area?{resolved}
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.
Last edited by System_Error; Jul 23rd, 2005 at 07:53 AM.
-
Jul 22nd, 2005, 01:45 PM
#2
Dazed Member
Re: Add MouseListeners to a canvas/drawing area?
Perhaps have the Canvas implement a MouseMotionListener for the mouse clicking and dragging. mouseDragged(MouseEvent e).
-
Jul 22nd, 2005, 03:15 PM
#3
Thread Starter
Frenzied Member
Re: Add MouseListeners to a canvas/drawing area?
 Originally Posted by Dilenger4
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?
-
Jul 23rd, 2005, 07:53 AM
#4
Thread Starter
Frenzied Member
Re: Add MouseListeners to a canvas/drawing area?
Alright, I figured this crap out. Thanks for the help dillenger.
-
Jul 24th, 2005, 05:56 PM
#5
Dazed Member
Re: Add MouseListeners to a canvas/drawing area?{resolved}
Just out of curiosity how did you fix the problem? Did you work with a JLayeredPane?
-
Jul 24th, 2005, 07:24 PM
#6
Thread Starter
Frenzied Member
Re: Add MouseListeners to a canvas/drawing area?{resolved}
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.
-
Jul 24th, 2005, 08:12 PM
#7
Dazed Member
Re: Add MouseListeners to a canvas/drawing area?{resolved}
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 Anyway. Try working with a JLayerPane and changing the Opacity. Maybe that might do the trick. Good Luck!
Last edited by Dilenger4; Jul 24th, 2005 at 08:15 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|