Path: blob/master/test/jdk/java/awt/Mouse/MouseWheelAbsXY/MouseWheelAbsXY.java
41152 views
/*1* Copyright (c) 2015, 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.AWTException;24import java.awt.Frame;25import java.awt.GraphicsConfiguration;26import java.awt.GraphicsDevice;27import java.awt.GraphicsEnvironment;28import java.awt.Robot;29import java.awt.Window;30import java.awt.event.InputEvent;3132import static java.awt.GraphicsEnvironment.*;3334/**35* @test36* @key headful37* @bug 677808738*/39public final class MouseWheelAbsXY {4041private static boolean done;42private static int wheelX;43private static int wheelY;44private static int mouseX;45private static int mouseY;4647public static void main(final String[] args) throws AWTException {48GraphicsEnvironment ge = getLocalGraphicsEnvironment();49GraphicsDevice[] sds = ge.getScreenDevices();50for (GraphicsDevice gd : sds) {51test(gd.getDefaultConfiguration());52}53}5455private static void test(GraphicsConfiguration gc) throws AWTException {56final Window frame = new Frame(gc);57try {58frame.addMouseWheelListener(e -> {59wheelX = e.getXOnScreen();60wheelY = e.getYOnScreen();61done = true;62});63frame.setSize(300, 300);64frame.setVisible(true);6566final Robot robot = new Robot();67robot.setAutoDelay(50);68robot.setAutoWaitForIdle(true);69mouseX = frame.getX() + frame.getWidth() / 2;70mouseY = frame.getY() + frame.getHeight() / 2;7172robot.mouseMove(mouseX, mouseY);73robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);74robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);75robot.mouseWheel(10);7677validate();78} finally {79frame.dispose();80}81}8283private static void validate() {84if (!done || wheelX != mouseX || wheelY != mouseY) {85System.err.println("Expected X: " + mouseX);86System.err.println("Expected Y: " + mouseY);87System.err.println("Actual X: " + wheelX);88System.err.println("Actual Y: " + wheelY);89throw new RuntimeException("Test failed");90}91}92}939495