Mouse Motion Listener?
Author |
Message |
[Gandalf]
|
Posted: Tue Oct 11, 2005 3:39 pm Post subject: Mouse Motion Listener? |
|
|
I read the java documentation on a bunch of the 'mouse' classes, but I'm not quite sure how to put it all together. I have tried various things to get the program to use the mouse, and this is the last:
Java: | public void paint (Graphics g )
{
addMouseMotionListener (m );
Circle. x = m. mouseMoved(m. getScreenX());
Circle. y = m. mouseMoved(m. getScreenY());
g. setColor(Color. white);
g. fillRect(0, 0, maxx, maxy ); //clear the screen
ball. move();
g. setColor(Color. red);
g. drawOval(ball. getX(), ball. getY(), ball. getRadius(), ball. getRadius());
g. setColor(Color. black);
g. drawRect(0, 0, maxx- 1, maxy- 1);
delay (20);
repaint ();
} |
I am fairly sure the problem is addMouseMotionListener, but I can't find or think of an alternative/fix for it. If you want to see the whole program, I can post it later, but this is the only part relating to mouse movement.
Once again, thanks for any help.
PS. I made Circle.x/y static for testing purposes. |
|
|
|
|
|
Sponsor Sponsor
|
|
|
wtd
|
Posted: Tue Oct 11, 2005 5:15 pm Post subject: (No subject) |
|
|
|
|
|
|
|
|
rizzix
|
Posted: Tue Oct 11, 2005 5:47 pm Post subject: Re: Mouse Motion Listener? |
|
|
[Gandalf] wrote: I read the java documentation on a bunch of the 'mouse' classes, but I'm not quite sure how to put it all together. I have tried various things to get the program to use the mouse, and this is the last:
Java: | public void paint (Graphics g )
{
addMouseMotionListener (m );
Circle. x = m. mouseMoved(m. getScreenX());
Circle. y = m. mouseMoved(m. getScreenY());
g. setColor(Color. white);
g. fillRect(0, 0, maxx, maxy ); //clear the screen
ball. move();
g. setColor(Color. red);
g. drawOval(ball. getX(), ball. getY(), ball. getRadius(), ball. getRadius());
g. setColor(Color. black);
g. drawRect(0, 0, maxx- 1, maxy- 1);
delay (20);
repaint ();
} |
I am fairly sure the problem is addMouseMotionListener, but I can't find or think of an alternative/fix for it. If you want to see the whole program, I can post it later, but this is the only part relating to mouse movement.
Once again, thanks for any help.
PS. I made Circle.x/y static for testing purposes.
ehm.. notice that you are adding a mouse listener everytime the paint method is called? just add it once.. in the init method |
|
|
|
|
|
|
|