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

MouseListener  RSS feed

 
Andrew Lit
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
i want that my application would be able to get the position of the mouse every time it is beeing moved.
So this is what i get, but it is not working

i would be very glad if someone looked through my code and pointed out my mistake.
thank you
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, I don't know if there is some code missing. And I don't know if you ever got yours to compile since you really didn't tell us what was not working. But here is a list of things that I found from you code:
1. You implement AcctionListener, and Runnable, yet you do not have a run() method or any actionPerformed() methods for these interfaces. So you should get a compile error.
2. title is never defined as any type. Compile error
3. mousemsg is never defined as any type. Compile error.
4. mouseX/mouseY - never defined. Compile error
5. offScreenImage - mever defined. Compile error
I would assume that maybe you have some other classes or there are some other methods you have left out of the code you gave us.
What exactly are you having problems with, if not what I stated above? What is happening that should not be or what is not happening that should be.
 
Andrew Lit
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually i forgot to mention that everything compiled fine because i hadn't posted all my code.
Imagine that everything is defined.
And one more thing that everything works exept that mouse event. What i mean is that when i move my mouse nothing happens although mousemsg should be drawn.
[ November 21, 2002: Message edited by: Andrew Lit ]
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Perhaps you want to repaint...
 
Andrew Lit
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Dirk Schreckmann:
Perhaps you want to repaint...

what exactly do you mean?
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
At the appropriate time (such as during the execution of some method - like maybe mouseEntered or mouseMoved) perhaps you want to explicitly refresh the display (by saying repaint()).
 
Andrew Lit
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Dirk Schreckmann:
At the appropriate time (such as during the execution of some method - like maybe mouseEntered or mouseMoved) perhaps you want to explicitly refresh the display (by saying repaint()).

i added that repaint(); line in every method, but i didn't work.
that mouse event is never caught. i feel .
[ November 23, 2002: Message edited by: Andrew Lit ]
 
Andrew Lit
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
maybe i should add one more thread(because i've already have one) specially for that mouse event?
[ November 24, 2002: Message edited by: Andrew Lit ]
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does this work for you?
 
Andrew Lit
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes this code works.
ok, i'll try to compare what i have and make some changes.
 
Andrew Lit
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
everything was ok, i only forgot
canvas = new Canvas();
canvas.addMouseMotionListener(this);
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!