MouseMovements


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: MouseMovements

  1. #1
    Join Date
    Aug 2005
    Posts
    14

    MouseMovements

    below is the code for my MouseMovements program

    import java.awt.*;
    import java.applet.*;
    import java.awt.event.*;

    public class MouseMovements extends Applet
    implements MouseListener, MouseMotionListener
    {
    String MouseDownMsg = null;
    String MouseUpMsg = null;
    String MouseDragMsg = null;


    public void init()
    {
    this.addMouseListener(this);
    this.addMouseMotionListener(this);
    }

    public void paint(Graphics g)
    {
    if (MouseUpMsg != null) g.drawString(MouseUpMsg, 5, 20);
    if (MouseDownMsg !=null) g.drawString(MouseDownMsg, 5, 40);
    if (MouseDragMsg !=null) g.drawString(MouseDragMsg, 5, 60);
    }
    public void mousePressed(MouseEvent event)
    {
    MouseUpMsg = "UP>" +event.getX() + "," + event.getY();
    repaint(); // call repaint()

    }
    public void mouseReleased(MouseEvent event)
    {
    MouseDownMsg = "DOWN>" +event.getX() + "," +event.getY();
    repaint(); // call repaint()

    }
    public void mouseClicked(MouseEvent event){};
    public void mouseExited(MouseEvent event){};
    public void mouseEntered(MouseEvent event){};

    public void mouseDraged(MouseEvent event)

    {
    MouseDragMsg = "DRAG>" +event.getX() + "," + event.getY();
    repaint(); // call repaint()

    }


    public void mouseMoved(MouseEvent event) {};
    }


    below is what the compiler is complaining about

    C:\Documents and Settings\ABK\My Documents\PA\MouseMovements.java:5: MouseMovements is not abstract and does not override abstract method mouseDragged(java.awt.event.MouseEvent) in java.awt.event.MouseMotionListener
    public class MouseMovements extends Applet
    ^
    1 error

    Tool completed with exit code 1

  2. #2
    Join Date
    Oct 2004
    Posts
    311
    you are implementing the MouseMotionListener.
    This is an interface which has several methods. All these methods have to be implemented in your code in order to correctly implement the interface.
    It apears that you forgot to implement the mouseDragged method.

  3. #3
    Join Date
    Nov 2004
    Location
    Norway
    Posts
    1,560
    Exactly, you have implemented the mouseDraged method, and that's a drag....
    eschew obfuscation

  4. #4
    Join Date
    Aug 2005
    Posts
    14

    mousemovements

    thanks for that

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center