JDK-4060084 : Phantom mouseReleased() bug in JDK 1.1.1/Win32
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 1.1.1
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_95
  • CPU: x86
  • Submitted: 1997-06-19
  • Updated: 1998-03-12
  • Resolved: 1998-03-12
Related Reports
Duplicate :  
Description

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 - ###@###.###
======================================================================

Comments
WORK AROUND Name: sgC58550 Date: 06/19/97 ======================================================================
11-06-2004