jdk/test/java/awt/Mouse/RemovedComponentMouseListener/RemovedComponentMouseListener.java
changeset 28985 33e7de0337d9
child 40128 e635645d2a8a
equal deleted inserted replaced
28984:12031ba2dc38 28985:33e7de0337d9
       
     1 /*
       
     2  * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
       
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       
     4  *
       
     5  * This code is free software; you can redistribute it and/or modify it
       
     6  * under the terms of the GNU General Public License version 2 only, as
       
     7  * published by the Free Software Foundation.
       
     8  *
       
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
       
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    12  * version 2 for more details (a copy is included in the LICENSE file that
       
    13  * accompanied this code).
       
    14  *
       
    15  * You should have received a copy of the GNU General Public License version
       
    16  * 2 along with this work; if not, write to the Free Software Foundation,
       
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    18  *
       
    19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
       
    20  * or visit www.oracle.com if you need additional information or have any
       
    21  * questions.
       
    22  */
       
    23 
       
    24 /*
       
    25  * @test
       
    26  * @bug 8061636
       
    27  * @summary fix for 7079254 changes behavior of MouseListener, MouseMotionListener
       
    28  * @library ../../regtesthelpers
       
    29  * @build Util
       
    30  * @author Alexander Zvegintsev
       
    31  * @run main RemovedComponentMouseListener
       
    32  */
       
    33 
       
    34 import java.awt.Robot;
       
    35 import java.awt.event.InputEvent;
       
    36 import java.awt.event.MouseAdapter;
       
    37 import java.awt.event.MouseEvent;
       
    38 import javax.swing.*;
       
    39 import test.java.awt.regtesthelpers.Util;
       
    40 
       
    41 public class RemovedComponentMouseListener extends JFrame {
       
    42 
       
    43     static boolean mouseReleasedReceived;
       
    44     static JButton button;
       
    45 
       
    46     public RemovedComponentMouseListener() {
       
    47         JPanel panel = new JPanel();
       
    48         JPanel buttonPanel = new JPanel();
       
    49         button = new JButton("Button");
       
    50 
       
    51         setSize(300, 300);
       
    52 
       
    53         buttonPanel.add(button);
       
    54         panel.add(buttonPanel);
       
    55         setContentPane(panel);
       
    56 
       
    57         button.addMouseListener(new MouseAdapter() {
       
    58             @Override
       
    59             public void mousePressed(MouseEvent e) {
       
    60                 buttonPanel.remove(button);
       
    61                 panel.add(button);
       
    62                 button.revalidate();
       
    63                 button.repaint();
       
    64             }
       
    65 
       
    66             @Override
       
    67             public void mouseReleased(MouseEvent e) {
       
    68                 mouseReleasedReceived = true;
       
    69             }
       
    70         });
       
    71 
       
    72         setVisible(true);
       
    73     }
       
    74 
       
    75     public static void main(String[] args) throws Exception {
       
    76         SwingUtilities.invokeAndWait(() -> {
       
    77             new RemovedComponentMouseListener();
       
    78         });
       
    79 
       
    80         Robot r = Util.createRobot();
       
    81         r.setAutoDelay(100);
       
    82         r.waitForIdle();
       
    83         Util.pointOnComp(button, r);
       
    84 
       
    85         r.waitForIdle();
       
    86         r.mousePress(InputEvent.BUTTON1_MASK);
       
    87         r.waitForIdle();
       
    88         r.mouseRelease(InputEvent.BUTTON1_MASK);
       
    89         r.waitForIdle();
       
    90         if (!mouseReleasedReceived) {
       
    91             throw new RuntimeException("mouseReleased event was not received");
       
    92         }
       
    93     }
       
    94 }