Path: blob/master/test/jdk/java/awt/MenuBar/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.Frame;31import java.awt.Menu;32import java.awt.MenuBar;33import java.awt.MenuItem;34import java.awt.TextArea;35import java.awt.event.ActionEvent;36import java.awt.event.ActionListener;3738public final class ActionEventTest extends Frame {3940MenuBar menuBar;41TextArea instructions;42public static boolean isProgInterruption = false;43static Thread mainThread = null;44static int sleepTime = 300000;4546public ActionEventTest() {47menuBar = new MenuBar();48Menu menu = new Menu("Menu1");49MenuItem menuItem = new MenuItem("MenuItem");5051menuItem.addActionListener(new ActionListener() {52@Override53public void actionPerformed(ActionEvent ae) {54System.out.println("actionPerformed");55int md = ae.getModifiers();56int expectedMask = ActionEvent.ALT_MASK | ActionEvent.CTRL_MASK57| ActionEvent.SHIFT_MASK;5859isProgInterruption = true;60mainThread.interrupt();61if ((md & expectedMask) != expectedMask) {62throw new RuntimeException("Action Event modifiers are not"63+ " set correctly.");64}65}66});67menu.add(menuItem);68menuBar.add(menu);69setMenuBar(menuBar);7071instructions = new TextArea(10, 50);72instructions.setText(73" This is a manual test\n" +74" Keep the Alt, Shift & Ctrl Keys pressed while doing next steps\n" +75" Click 'Menu1' Menu from the Menu Bar\n" +76" It will show 'MenuItem'\n" +77" Left mouse Click the 'MenuItem'\n" +78" Test exits automatically after mouse click.");79add(instructions);8081setSize(400, 400);82setVisible(true);83validate();84}858687public static void main(final String[] args) throws Exception {88mainThread = Thread.currentThread();89ActionEventTest test = new ActionEventTest();90try {91mainThread.sleep(sleepTime);92} catch (InterruptedException e) {93if (!isProgInterruption) {94throw e;95}96}97test.dispose();98if (!isProgInterruption) {99throw new RuntimeException("Timed out after " + sleepTime / 1000100+ " seconds");101}102}103}104105106