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