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

Phantom mouseReleased() bug in JDK 1.1.1/Win32

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 1.1.1
    • client-libs
    • None
    • x86
    • windows_95



      Name: sgC58550 Date: 06/19/97


      The following program demonstrates a mouse handling bug in the
      JDK 1.1.1/Win32 AWT. When run, the program puts up two white
      buttons which each take up half of the application's window
      (vertically). If you press the left mouse button on the top
      one, then drag the cursor to the bottom one and release the left
      button, the top button (correctly) changes color to show that it
      was pressed, then changes back to its original color. It prints
      a message to the console indicating that it got a mouseReleased()
      event.

      If you then move the mouse so that it is over the top button
      again, it receives a second mouseReleased() event even though
      the mouse button was not released, nor pressed, a second time.

      // PhantomReleaseBug.java

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

      class MyButton extends Canvas
      {
          private boolean down;
          private String myName;

          public MyButton(String name)
          {
              myName = name;
              addMouseListener(
                  new MouseAdapter()
                  {
                      public void mousePressed(MouseEvent e)
                      {
                          down = true;
                          repaint();
                      }

                      public void mouseReleased(MouseEvent e)
                      {
                          down = false;
                          System.out.println(myName + " got mouseReleased message");
                          repaint();
                      }
                  }
              );
          }

          public void paint(Graphics g)
          {
              g.setColor(Color.white);
              g.fill3DRect(0, 0, getSize().width, getSize().height, !down);
          }

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

      }

      public class PhantomReleaseBug extends Frame
      {
          public static void main(String args[])
          {
              new PhantomReleaseBug();
          }

          private PhantomReleaseBug()
          {
              super("Phantom Release Bug");
              addWindowListener(
                  new WindowAdapter()
                  {
                      public void windowClosing(WindowEvent e) { System.exit(0); }
                  }
              );
              add("North", new MyButton("Top"));
              add("South", new MyButton("Bottom"));
              setVisible(true);
              pack();
          }
      }

      company - Worlds, Inc. , email - ###@###.###
      ======================================================================

            feckssunw Fred Ecks (Inactive)
            sgoodsunw Sheri Good (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: