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

Mouse entered events give the wrong coordinate

XMLWordPrintable

    • x86
    • windows_nt



      Name: joT67522 Date: 12/08/97


      The code below illustrates the problem. Take any two
      components and add a mouselistener for enter and
      exit events for each component. Place the components
      in a container such that they are adjoining.
      As the mouse exits component A and enters component
      B, the mouse entered event for component B gives the
      coordinate at which the mouse exited for component
      A.

      NB. this is a serious problem in drawing applications.

      Here is some code:
      /*
       * This applet demonstrates a bug with the mouse entered event.
       * Two panels are placed side by side. When the mouse moves across the
       * border between the panels, a mouse exit event is generated and then
       * an entered event.
       * Note that the coordinate for both is the same - the coordinate for
       * the mouse entered event should be the point at which the mouse
       * entered the panel, not the point at which the mouse exited the
       * adjoining panel.
       *
       * Channing Walton
       * ###@###.###
       */

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

      public class Applet1 extends Applet
      {
      public void init()
      {

      setLayout(null);
      panel1 = new java.awt.Panel();
      panel1.setBounds(0,0,100,100);
      panel1.setBackground(new Color(12632256));
      add(panel1);
      panel2 = new java.awt.Panel();
      panel2.setBounds(100,0,100,100);
      panel2.setBackground(new Color(16756655));
      add(panel2);

      SymMouse aSymMouse = new SymMouse();
      panel1.addMouseListener(aSymMouse);
      panel2.addMouseListener(aSymMouse);
      }

      java.awt.Panel panel1;
      java.awt.Panel panel2;

      class SymMouse extends java.awt.event.MouseAdapter
      {
      public void mouseExited(java.awt.event.MouseEvent event)
      {
      System.out.println("Exit: " + event.getPoint());
      }

      public void mouseEntered(java.awt.event.MouseEvent event)
      {
      System.out.println("Entered: " + event.getPoint());
      }
      }
      }
      (Review ID: 21532)
      ======================================================================

            rramsunw Ranganathan Ram (Inactive)
            johsunw Joon Oh (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: