Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Mouse Motion Listener?
Index -> Programming, Java -> Java Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
[Gandalf]




PostPosted: 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
Sponsor
sponsor
wtd




PostPosted: Tue Oct 11, 2005 5:15 pm   Post subject: (No subject)

Java:
public class MyClass extends JApplet implements MouseMotionListener
{
   public void init()
   {

   }

   public void paint(Graphics g)
   {

   }

   void mouseDragged(MouseEvent e)
   {

   }

   void mouseMoved(MouseEvent e)
   {

   }
}
rizzix




PostPosted: 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
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 3 Posts ]
Jump to:   


Style:  
Search: