Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4138129

Dragging mouse causes a mouseMoved event

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Cannot Reproduce
    • Icon: P4 P4
    • None
    • 1.1.6
    • client-libs
    • sparc
    • solaris_2.6



      Name: el35337 Date: 05/13/98


      Create a canvas that implements MouseMotionListener.
      In the method mouseMoved add an if-statement that checks
      to see if any of the buttons are pressed. If so, display
      a message.
        Here is a code sample, just add this component to
      a frame and drag the mouse inside it.

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

      public class DragTest extends Canvas implements MouseListener, MouseMotionListener {

        Point now_at, was_at;

        public DragTest () {
          now_at = new Point(100,100);
          was_at = null;
          setBackground(Color.lightGray);
          addMouseListener(this);
          addMouseMotionListener(this);
        }

        private void drawHandle(Graphics g, Point where_at) {
          g.setXORMode(getBackground());
          g.drawLine(where_at.x, where_at.y-5, where_at.x, where_at.y+5);
          g.drawLine(where_at.x-5, where_at.y, where_at.x+5, where_at.y);
          g.drawOval(where_at.x-3, where_at.y-3, 6, 6);
        }
          

        public Dimension getMinimumSize() {
          return getPreferredSize();
        }

        public Dimension getPreferredSize() {
          return new Dimension (300,300);
        }

        public void mouseClicked(MouseEvent ev) {}
        public void mouseDragged(MouseEvent ev) {
          now_at.x = ev.getX();
          now_at.y = ev.getY();
          repaint();
        }
        public void mouseEntered(MouseEvent ev) {}
        public void mouseExited(MouseEvent ev) {}
        public void mouseMoved(MouseEvent ev) {
          if ( ((ev.getModifiers() & MouseEvent.BUTTON1_MASK) > 0) ||
      ((ev.getModifiers() & MouseEvent.BUTTON1_MASK) > 0) ||
      ((ev.getModifiers() & MouseEvent.BUTTON1_MASK) > 0) )
            System.out.println("Mouse 'moved' with a button pressed! Ain't that a 'drag'?");
        }
        public void mousePressed(MouseEvent ev) {}
        public void mouseReleased(MouseEvent ev) {}

        public void paint(Graphics g) {

          if (was_at != null)
            drawHandle(g, was_at);
          else
            was_at = new Point(0,0);

          drawHandle(g, now_at);
          was_at.x = now_at.x;
          was_at.y = now_at.y;
        }

        public void update(Graphics g) {
          paint(g);
        }
      }


        I compiled this program with JDK 1.1.6 on Solaris 2.6
      Sparc. Here are the results of running this program
      on various platforms:
      Solaris 2.6 Solaris 2.6 WinNT 4.0
      Sparc Sparc Intel
      OpenWindows CDE Pentium II
      ------------------------------------------------------------
      Java 1.1.6 Bad Bad (not tested)
       JRE 1.1.6 Bad Bad Good
      Java 1.1.2 Good Good Good
      (Review ID: 29478)
      ======================================================================

            duke J. Duke
            elarsen Erik Larsen (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: