1/* 2 * Copyright (c) 2017, 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 24import java.awt.Frame; 25import java.awt.GraphicsDevice; 26import java.awt.GraphicsEnvironment; 27import java.awt.Rectangle; 28import java.awt.Robot; 29import java.awt.event.MouseAdapter; 30import java.awt.event.MouseEvent; 31 32/** 33 * @test 34 * @key headful 35 * @bug 8176009 36 */ 37public class MultiScreenRobotPosition { 38 39 private static volatile boolean fail = true; 40 41 public static void main(String[] args) throws Exception { 42 GraphicsDevice[] sds = GraphicsEnvironment.getLocalGraphicsEnvironment() 43 .getScreenDevices(); 44 for (final GraphicsDevice gd : sds) { 45 fail = true; 46 Robot robot = new Robot(gd); 47 robot.setAutoDelay(100); 48 robot.setAutoWaitForIdle(true); 49 50 Frame frame = new Frame(gd.getDefaultConfiguration()); 51 frame.setUndecorated(true); 52 frame.setSize(400, 400); 53 frame.setVisible(true); 54 robot.waitForIdle(); 55 56 frame.addMouseListener(new MouseAdapter() { 57 @Override 58 public void mouseClicked(MouseEvent e) { 59 System.out.println("e = " + e); 60 fail = false; 61 } 62 }); 63 64 Rectangle bounds = frame.getBounds(); 65 robot.mouseMove(bounds.x + bounds.width / 2, 66 bounds.y + bounds.height / 2); 67 robot.mousePress(MouseEvent.BUTTON1_DOWN_MASK); 68 robot.mouseRelease(MouseEvent.BUTTON1_DOWN_MASK); 69 frame.dispose(); 70 if (fail) { 71 System.err.println("Frame bounds = " + bounds); 72 throw new RuntimeException("Click in the wrong location"); 73 } 74 } 75 } 76} 77