Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/awt/Choice/GrabLockTest/GrabLockTest.java
47525 views
/*1* Copyright (c) 2003, 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*/22/*23@test24@bug 480063825@summary Tests that Choice does not lock the Desktop26@run main GrabLockTest27*/28import java.awt.*;29import java.awt.event.*;3031public class GrabLockTest32{33public static void main (String args[])34{35Frame frame = new TestFrame();36}37}3839class TestFrame extends Frame implements MouseListener {40public TestFrame() {41Choice choice = new Choice();42choice.addItem("Fist Item");43choice.addItem("Second Item");44add(choice,BorderLayout.NORTH);45Panel panel = new Panel();46panel.addMouseListener(this);47panel.setBackground(Color.RED);48add(panel);49setSize(200, 200);50setVisible(true);51toFront();5253try {54Robot robot = new Robot();55robot.setAutoWaitForIdle(true);56robot.setAutoDelay(50);5758robot.waitForIdle();5960Point pt = choice.getLocationOnScreen();61robot.mouseMove(pt.x + choice.getWidth() - choice.getHeight()/2,62pt.y + choice.getHeight()/2);63robot.mousePress(InputEvent.BUTTON1_MASK);64robot.waitForIdle();65robot.mouseMove(pt.x + choice.getWidth()/2,66pt.y + choice.getHeight()*2);67robot.waitForIdle();68robot.mousePress(InputEvent.BUTTON2_MASK);69robot.waitForIdle();70Point pt1 = panel.getLocationOnScreen();71robot.mouseMove(pt1.x + panel.getWidth()/2,72pt1.y + panel.getHeight()/2);73robot.waitForIdle();74robot.mouseRelease(InputEvent.BUTTON1_MASK);75robot.mouseRelease(InputEvent.BUTTON2_MASK);7677robot.waitForIdle();7879robot.mousePress(InputEvent.BUTTON1_MASK);80robot.delay(30);81robot.mouseRelease(InputEvent.BUTTON1_MASK);82robot.waitForIdle();83if (nPressed == 0) {84robot.keyPress(KeyEvent.VK_ESCAPE);85robot.keyRelease(KeyEvent.VK_ESCAPE);86throw new RuntimeException("GrabLockTest failed." + nPressed);87}88} catch (Exception e) {89throw new RuntimeException("The test was not completed.\n\n" + e);90}9192}9394public int nPressed = 0;9596public void mouseClicked(MouseEvent e) {97}9899public void mousePressed(MouseEvent e) {100nPressed++;101System.out.println("Pressed!");102}103104public void mouseReleased(MouseEvent e) {105}106107public void mouseEntered(MouseEvent e) {}108public void mouseExited(MouseEvent e) {}109}// class TestFrame110111112