Results 1 to 7 of 7

Thread: Add MouseListeners to a canvas/drawing area?{resolved}

  1. #1

    Thread Starter
    Frenzied Member System_Error's Avatar
    Join Date
    Apr 2004
    Posts
    1,111

    Resolved 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.

  2. #2
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418

    Re: Add MouseListeners to a canvas/drawing area?

    Perhaps have the Canvas implement a MouseMotionListener for the mouse clicking and dragging. mouseDragged(MouseEvent e).

  3. #3

    Thread Starter
    Frenzied Member System_Error's Avatar
    Join Date
    Apr 2004
    Posts
    1,111

    Re: Add MouseListeners to a canvas/drawing area?

    Quote 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?

  4. #4

    Thread Starter
    Frenzied Member System_Error's Avatar
    Join Date
    Apr 2004
    Posts
    1,111

    Re: Add MouseListeners to a canvas/drawing area?

    Alright, I figured this crap out. Thanks for the help dillenger.

  5. #5
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418

    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?

  6. #6

    Thread Starter
    Frenzied Member System_Error's Avatar
    Join Date
    Apr 2004
    Posts
    1,111

    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.

  7. #7
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418

    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!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width