Path: blob/master/test/jdk/java/awt/Mixing/AWT_Mixing/FrameBorderCounter.java
41152 views
/*1* Copyright (c) 2014, 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.Dimension;24import java.awt.EventQueue;25import java.awt.Frame;26import java.awt.Point;27import java.awt.Robot;28import java.awt.event.MouseAdapter;29import java.awt.event.MouseEvent;3031public class FrameBorderCounter {3233private static Frame frame;34private static Frame background;35private static Dimension size;36private static Point location;37private static Point entered;3839public static void main(String[] args) throws Exception {40final Robot robot = new Robot();41EventQueue.invokeAndWait(new Runnable() {42public void run() {43robot.mouseMove(0, 0);44}45});46EventQueue.invokeAndWait(new Runnable() {47public void run() {48background = new Frame();49background.setBounds(100, 100, 300, 300);50background.addMouseListener(new MouseAdapter() {51@Override52public void mouseEntered(MouseEvent e) {53entered = e.getLocationOnScreen();54System.err.println("[ENTERED] : " + entered);55}56});57background.setVisible(true);58}59});60robot.waitForIdle();61EventQueue.invokeAndWait(new Runnable() {62public void run() {63frame = new Frame("Frame");64frame.setBounds(200, 200, 100, 100);65frame.setVisible(true);66}67});68Thread.sleep(1000);69EventQueue.invokeAndWait(new Runnable() {70public void run() {71location = frame.getLocationOnScreen();72size = frame.getSize();73}74});75int out = 20;76for (int x = location.x + size.width - out; x <= location.x + size.width + out; ++x) {77robot.mouseMove(x, location.y + size.height / 2);78Thread.sleep(50);79}80System.err.println("[LOCATION] : " + location);81System.err.println("[SIZE] : " + size);82Thread.sleep(250);83int shift = entered.x - location.x - size.width - 1;84System.err.println("Done");85System.out.println(shift);86frame.dispose();87background.dispose();88}89}909192