
-----------------------------------
[Gandalf]
Tue Oct 11, 2005 3:39 pm

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:
	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.

-----------------------------------
wtd
Tue Oct 11, 2005 5:15 pm


-----------------------------------
public class MyClass extends JApplet implements MouseMotionListener
{
   public void init() 
   {

   }

   public void paint(Graphics g)
   {

   }

   void mouseDragged(MouseEvent e)
   {

   }

   void mouseMoved(MouseEvent e)
   {

   }
}

-----------------------------------
rizzix
Tue Oct 11, 2005 5:47 pm

Re: 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:
	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
