Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Painting mouse movement over an applet  RSS feed

 
Kieran Webster
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm looking to paint the mouse movement over an applet by just simply drawing a line, and the line will follow where ever the mouse moves.

I'm loading an Applet from an external source, but I can't seem to get it to work using JApplet. Can someone take a look at this code and correct?

 
Campbell Ritchie
Sheriff
Posts: 53742
127
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I can see several errors:
  • Two members of that class marked static
  • Overriding repaint(). You should override paintComponent()
  • You may need to cast the Graphics object to Graphics2D in order to use some of its methods.
     
    Kieran Webster
    Greenhorn
    Posts: 22
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Alright I removed the static on the fields and here is the new paintComponent method



    It still doesn't seem to be painting my mouse movement. What am I missing?

    Edit: Even tried handling the mouse movement/painting in a separate class and still nothing.
     
    Campbell Ritchie
    Sheriff
    Posts: 53742
    127
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    I tried running your code and got compiler errors by the dozen.
     
    m Korbel
    Ranch Hand
    Posts: 174
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Crossposted ???
     
    Kieran Webster
    Greenhorn
    Posts: 22
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Campbell Ritchie wrote:I tried running your code and got compiler errors by the dozen.


    Yeah that's because there's more, but the other methods just get the applet data, and some JMenuBar items.

    I tried making a separate applet to just test if the mouse movement was working or not.


    m Korbel wrote:Crossposted ???


    Yeah I posted here as that was no help. My question was misunderstood.


    This doesn't seem to be working either



    Any guidance..?

    Edit: I have got tracking mouse movement to work using mouse listener, except it doesn't apply to the applet I'm using. No matter what I try it will work anywhere else, but the applet window.
     
    Campbell Ritchie
    Sheriff
    Posts: 53742
    127
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Kieran Webster wrote: . . . My question was misunderstood. . . .
    I don’t think your question was misunderstood there at all. I think you were given a good answer. You have however managed to copy it wrongly. And please look at this.

    Not only did your code fail to compile because it was incomplete, but also because there were errors like having the mouseClicked method in a MouseMotionListener.
     
    Campbell Ritchie
    Sheriff
    Posts: 53742
    127
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    I see some of those errors were in the SO post, too. Sorry for blaming you for them.
     
    Kieran Webster
    Greenhorn
    Posts: 22
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Alright my bad with the cross posting, ill make sure I provide links if it is to happen again.

    I think what I have now works, it's printing mouse movement to the console, but it's still not working for the actual applet, and yes I have added a listener to the applet.

    How can I make it so it tracks over the applet?
     
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!