Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/awt/Mixing/AWT_Mixing/FrameBorderCounter.java
47626 views
/*1* Copyright (c) 2014, 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*/22import java.awt.Dimension;23import java.awt.EventQueue;24import java.awt.Frame;25import java.awt.Point;26import java.awt.Robot;27import java.awt.event.MouseEvent;28import java.awt.event.MouseAdapter;29import java.awt.event.WindowEvent;30import java.awt.event.WindowAdapter;3132public class FrameBorderCounter {3334private static Frame frame;35private static Frame background;36private static Dimension size;37private static Point location;38private static Point entered;3940public static void main(String[] args) throws Exception {41final Robot robot = new Robot();42EventQueue.invokeAndWait(new Runnable() {43public void run() {44robot.mouseMove(0, 0);45}46});47EventQueue.invokeAndWait(new Runnable() {48public void run() {49background = new Frame();50background.setBounds(100, 100, 300, 300);51background.addMouseListener(new MouseAdapter() {52@Override53public void mouseEntered(MouseEvent e) {54entered = e.getLocationOnScreen();55System.err.println("[ENTERED] : " + entered);56}57});58background.setVisible(true);59}60});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