Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/awt/Mouse/TitleBarDoubleClick/TitleBarDoubleClick.java
47490 views
/*1* Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24test25@bug 466441526@summary REGRESSION: double click jframe titlebar generating mouse events in panel27@author Andrei Dmitriev: area=awt.mouse28@run applet TitleBarDoubleClick.html29*/30import java.applet.Applet;31import java.awt.*;32import java.awt.event.*;33import test.java.awt.regtesthelpers.Util;3435public class TitleBarDoubleClick extends Applet implements MouseListener,36WindowListener37{38//Declare things used in the test, like buttons and labels here39private final static Rectangle BOUNDS = new Rectangle(300, 300, 300, 300);40private final static int TITLE_BAR_OFFSET = 10;4142Frame frame;43Robot robot;4445public void init()46{47this.setLayout (new BorderLayout ());4849}//End init()5051public void start ()52{53//Get things going. Request focus, set size, et cetera54setSize (200,200);55setVisible(true);56validate();5758//What would normally go into main() will probably go here.59//Use System.out.println for diagnostic messages that you want60//to read after the test is done.61//Use Sysout.println for messages you want the tester to read.6263robot = Util.createRobot();64robot.setAutoDelay(100);65robot.mouseMove(BOUNDS.x + (BOUNDS.width / 2),66BOUNDS.y + (BOUNDS.height/ 2));6768frame = new Frame("TitleBarDoubleClick");69frame.setBounds(BOUNDS);70frame.addMouseListener(this);71frame.addWindowListener(this);72frame.setVisible(true);73Util.waitForIdle(robot);74}// start()7576// Move the mouse into the title bar and double click to maximize the77// Frame78static boolean hasRun = false;7980private void doTest() {81if (hasRun) return;82hasRun = true;8384System.out.println("doing test");85robot.mouseMove(BOUNDS.x + (BOUNDS.width / 2),86BOUNDS.y + TITLE_BAR_OFFSET);87robot.delay(50);88// Util.waitForIdle(robot) seem always hangs here.89// Need to use it instead robot.delay() when the bug become fixed.90System.out.println("1st press: currentTimeMillis: " + System.currentTimeMillis());91robot.mousePress(InputEvent.BUTTON1_MASK);92robot.delay(50);93System.out.println("1st release: currentTimeMillis: " + System.currentTimeMillis());94robot.mouseRelease(InputEvent.BUTTON1_MASK);95robot.delay(50);96System.out.println("2nd press: currentTimeMillis: " + System.currentTimeMillis());97robot.mousePress(InputEvent.BUTTON1_MASK);98robot.delay(50);99System.out.println("2nd release: currentTimeMillis: " + System.currentTimeMillis());100robot.mouseRelease(InputEvent.BUTTON1_MASK);101System.out.println("done: currentTimeMillis: " + System.currentTimeMillis());102}103104private void fail() {105throw new AWTError("Test failed");106}107108public void mouseEntered(MouseEvent e) {}109public void mouseExited(MouseEvent e) {}110public void mousePressed(MouseEvent e) {fail();}111public void mouseReleased(MouseEvent e) {fail();}112public void mouseClicked(MouseEvent e) {fail();}113114public void windowActivated(WindowEvent e) {doTest();}115public void windowClosed(WindowEvent e) {}116public void windowClosing(WindowEvent e) {}117public void windowDeactivated(WindowEvent e) {}118public void windowDeiconified(WindowEvent e) {}119public void windowIconified(WindowEvent e) {}120public void windowOpened(WindowEvent e) {}121122}// class TitleBarDoubleClick123124125