Friday, 3 May 2013

MouseMotionListener

I'm moving on to making it possible to click onto objects in the room. To do that, I have to know the coordinates of the object, so I used the .getX() and .getY() methods. The coordinates will be printed out on a separate screen.
I tried using the MouseListener at first, but when I did that, the coordinates didn't show up when I tried it--I could only see the coordinates if it passed by a button.
Then I used MouseMotionListener and added it to the JFrame I want it to show up in. And I printed out the coordinates in the mouseMoved method. This worked out so one part is solved!!
...Maybe the mouseEntered didn't work because I didn't add the MouseListener to it...

3 comments:

  1. Isn't the MouseMotionListener and the MouseListener two entirely different things? O_O

    ReplyDelete
    Replies
    1. Yeah they are, but the MouseListener has a method (I don't remember which I was trying to use) that could help me with the same thing, but Ryk said to use the MouseMotionListner.

      Delete
    2. mouseEntered :D i think.

      Delete