Path: blob/master/test/jdk/java/awt/Mouse/GetMousePositionTest/GetMousePositionWithOverlay.java
41153 views
/*1* Copyright (c) 2013, 2018, 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*/2223import java.awt.Frame;24import java.awt.Point;25import java.awt.Robot;26import java.awt.Rectangle;2728/*29* @test30* @key headful31* @bug 8012026 819643532* @summary Component.getMousePosition() does not work in an applet on MacOS33* @run main GetMousePositionWithOverlay34*/3536public class GetMousePositionWithOverlay {3738private static Frame backFrame;39private static Frame frontFrame;40private static Robot robot;4142public static void main(String[] args) throws Throwable {43robot = new Robot();4445try{46constructTestUI();47} catch (Exception e) {48dispose();49throw new RuntimeException("Unexpected Exception!");50}5152robot.waitForIdle();5354doTest();55dispose();56}5758private static void doTest() {5960frontFrame.toFront();61robot.waitForIdle();6263Rectangle bounds = new Rectangle(frontFrame.getLocationOnScreen(), frontFrame.getSize());64robot.mouseMove(bounds.x + bounds.width / 2, bounds.y + bounds.height / 2);65robot.waitForIdle();6667Point pos = backFrame.getMousePosition();68if (pos != null) {69dispose();70throw new RuntimeException("Test failed. Mouse position should be null but was " + pos);71}7273pos = frontFrame.getMousePosition();74if (pos == null) {75dispose();76throw new RuntimeException("Test failed. Mouse position should not be null");77}7879robot.mouseMove(189, 189);80robot.waitForIdle();8182pos = backFrame.getMousePosition();83if (pos == null) {84dispose();85throw new RuntimeException("Test failed. Mouse position should not be null");86}8788}8990private static void dispose() {9192if (backFrame != null) {93backFrame.dispose();94}9596if (frontFrame != null) {97frontFrame.dispose();98}99}100101private static void constructTestUI() {102backFrame = new Frame();103backFrame.setBounds(100, 100, 100, 100);104backFrame.setResizable(false);105backFrame.setVisible(true);106107frontFrame = new Frame();108frontFrame.setBounds(120, 120, 60, 60);109frontFrame.setResizable(false);110frontFrame.setVisible(true);111112}113}114115116117