|
| 1 | +/* |
| 2 | + * Copyright (c) 2000, 2023, 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 4323121 |
| 27 | + * @summary Tests whether any button that extends JButton always |
| 28 | + returns true for isArmed() |
| 29 | + * @key headful |
| 30 | + * @run main bug4323121 |
| 31 | + */ |
| 32 | + |
| 33 | +import java.awt.Graphics; |
| 34 | +import java.awt.Point; |
| 35 | +import java.awt.Robot; |
| 36 | +import java.awt.event.MouseEvent; |
| 37 | +import java.awt.event.MouseListener; |
| 38 | +import java.awt.event.MouseMotionListener; |
| 39 | +import javax.swing.JButton; |
| 40 | +import javax.swing.JFrame; |
| 41 | +import javax.swing.SwingUtilities; |
| 42 | + |
| 43 | +public class bug4323121 { |
| 44 | + |
| 45 | + static JFrame frame; |
| 46 | + static testButton button; |
| 47 | + static volatile Point pt; |
| 48 | + static volatile int buttonW; |
| 49 | + static volatile int buttonH; |
| 50 | + static volatile boolean failed = false; |
| 51 | + |
| 52 | + public static void main(String[] args) throws Exception { |
| 53 | + Robot robot = new Robot(); |
| 54 | + robot.setAutoDelay(100); |
| 55 | + try { |
| 56 | + SwingUtilities.invokeAndWait(() -> { |
| 57 | + frame = new JFrame("bug4323121"); |
| 58 | + button = new testButton("gotcha"); |
| 59 | + frame.getContentPane().add(button); |
| 60 | + frame.pack(); |
| 61 | + frame.setLocationRelativeTo(null); |
| 62 | + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); |
| 63 | + frame.setVisible(true); |
| 64 | + }); |
| 65 | + robot.waitForIdle(); |
| 66 | + robot.delay(1000); |
| 67 | + SwingUtilities.invokeAndWait(() -> { |
| 68 | + pt = button.getLocationOnScreen(); |
| 69 | + buttonW = button.getSize().width; |
| 70 | + buttonH = button.getSize().height; |
| 71 | + }); |
| 72 | + robot.mouseMove(pt.x + buttonW / 2, pt.y + buttonH / 2); |
| 73 | + robot.waitForIdle(); |
| 74 | + if (failed) { |
| 75 | + throw new RuntimeException("Any created button returns " + |
| 76 | + "true for isArmed()"); |
| 77 | + } |
| 78 | + } finally { |
| 79 | + SwingUtilities.invokeAndWait(() -> { |
| 80 | + if (frame != null) { |
| 81 | + frame.dispose(); |
| 82 | + } |
| 83 | + }); |
| 84 | + } |
| 85 | + } |
| 86 | + |
| 87 | + static class testButton extends JButton implements MouseMotionListener, MouseListener { |
| 88 | + public testButton(String label) { |
| 89 | + super(label); |
| 90 | + addMouseMotionListener(this); |
| 91 | + addMouseListener(this); |
| 92 | + } |
| 93 | + |
| 94 | + protected void paintComponent(Graphics g) { |
| 95 | + super.paintComponent(g); |
| 96 | + } |
| 97 | + |
| 98 | + protected void paintBorder(Graphics g) { |
| 99 | + } |
| 100 | + |
| 101 | + public void mousePressed(MouseEvent e) { |
| 102 | + } |
| 103 | + |
| 104 | + public void mouseDragged(MouseEvent e) { |
| 105 | + } |
| 106 | + |
| 107 | + public void mouseMoved(MouseEvent e) { |
| 108 | + } |
| 109 | + |
| 110 | + public void mouseReleased(MouseEvent e) { |
| 111 | + } |
| 112 | + |
| 113 | + public void mouseEntered(MouseEvent e) { |
| 114 | + if (getModel().isArmed()) { |
| 115 | + failed = true; |
| 116 | + } |
| 117 | + } |
| 118 | + |
| 119 | + public void mouseExited(MouseEvent e) { |
| 120 | + } |
| 121 | + |
| 122 | + public void mouseClicked(MouseEvent e) { |
| 123 | + } |
| 124 | + } |
| 125 | +} |
0 commit comments