Path: blob/master/test/jdk/java/awt/List/ActionEventTest/ActionEventTest.java
41153 views
/*1* Copyright (c) 2016, 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*/2223/*24* @test25* @key headful26* @bug 6191390 815838027* @summary Verify that ActionEvent is received with correct modifiers set.28* @run main ActionEventTest29*/3031import java.awt.AWTException;32import java.awt.FlowLayout;33import java.awt.Frame;34import java.awt.List;35import java.awt.Robot;36import java.awt.event.ActionEvent;37import java.awt.event.ActionListener;38import java.awt.event.KeyEvent;3940public class ActionEventTest extends Frame {41List list;42Robot robot;4344public ActionEventTest() {45try {46robot = new Robot();47robot.setAutoDelay(100);48robot.setAutoWaitForIdle(true);49} catch(AWTException e) {50throw new RuntimeException(e.getMessage());51}5253list = new List(1, false);54list.add("0");55add(list);56setSize(400,400);57setLayout(new FlowLayout());58pack();59setVisible(true);60}6162void performTest() {63list.addActionListener(new ActionListener() {64@Override65public void actionPerformed(ActionEvent ae) {66int md = ae.getModifiers();67int expectedMask = ActionEvent.ALT_MASK | ActionEvent.CTRL_MASK68| ActionEvent.SHIFT_MASK;6970if ((md & expectedMask) != expectedMask) {7172robot.keyRelease(KeyEvent.VK_ALT);73robot.keyRelease(KeyEvent.VK_SHIFT);74robot.keyRelease(KeyEvent.VK_CONTROL);75dispose();76throw new RuntimeException("Action Event modifiers are not"77+ " set correctly.");78}79}80});8182list.select(0);83robot.keyPress(KeyEvent.VK_ALT);84robot.keyPress(KeyEvent.VK_SHIFT);85robot.keyPress(KeyEvent.VK_CONTROL);86// Press Enter on list item, to generate action event.87robot.keyPress(KeyEvent.VK_ENTER);88robot.keyRelease(KeyEvent.VK_ENTER);89robot.keyRelease(KeyEvent.VK_ALT);90robot.keyRelease(KeyEvent.VK_SHIFT);91robot.keyRelease(KeyEvent.VK_CONTROL);92}9394public static void main(String args[]) {95ActionEventTest test = new ActionEventTest();96test.performTest();97test.dispose();98}99}100101102