Path: blob/master/test/jdk/java/awt/Button/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* @bug 619139026* @summary Verify that ActionEvent is received with correct modifiers set.27* @run main/manual ActionEventTest28*/2930import java.awt.AWTException;31import java.awt.FlowLayout;32import java.awt.Frame;33import java.awt.Button;34import java.awt.TextArea;35import java.awt.Robot;36import java.awt.Point;37import java.awt.event.InputEvent;38import java.awt.event.ActionEvent;39import java.awt.event.ActionListener;40import java.awt.event.KeyEvent;4142public class ActionEventTest extends Frame {43Button button;44Robot robot;45TextArea instructions;46public static boolean isProgInterruption = false;47static Thread mainThread = null;48static int sleepTime = 300000;4950public ActionEventTest() {51try {52robot = new Robot();53} catch(AWTException e) {54throw new RuntimeException(e.getMessage());55}5657button = new Button("ClickMe");58button.setEnabled(true);5960instructions = new TextArea(10, 50);61instructions.setText(62" This is a manual test\n" +63" Keep the Alt, Shift & Ctrl Keys pressed &\n" +64" Click 'ClickMe' button with left mouse button\n" +65" Test exits automatically after mouse click.");6667add(button);68add(instructions);69setSize(400,400);70setLayout(new FlowLayout());71pack();72setVisible(true);73robot.waitForIdle();7475button.addActionListener(new ActionListener() {76@Override77public void actionPerformed(ActionEvent ae) {78int md = ae.getModifiers();79int expectedMask = ActionEvent.ALT_MASK | ActionEvent.CTRL_MASK80| ActionEvent.SHIFT_MASK;8182isProgInterruption = true;83mainThread.interrupt();84if ((md & expectedMask) != expectedMask) {85throw new RuntimeException("Action Event modifiers"86+ " are not set correctly.");87}88}89});90}9192public static void main(String args[]) throws Exception {93mainThread = Thread.currentThread();94ActionEventTest test = new ActionEventTest();95try {96mainThread.sleep(sleepTime);97} catch (InterruptedException e) {98if (!isProgInterruption) {99throw e;100}101}102test.dispose();103if (!isProgInterruption) {104throw new RuntimeException("Timed out after " + sleepTime / 1000105+ " seconds");106}107}108}109110111