Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/swing/JMenuItem/4171437/bug4171437.java
38854 views
/*1* Copyright (c) 2013, 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/* @test23@bug 417143724@library ../../regtesthelpers25@build Util26@author Georges Saab27@run main bug417143728*/29import java.awt.*;30import java.awt.event.*;31import java.util.ArrayList;32import javax.swing.*;33import javax.swing.event.*;3435public class bug4171437 {36static volatile boolean closeActivated = false;37static volatile boolean customActivated = false;3839public static void main(String[] args) throws Exception {40SwingUtilities.invokeAndWait(new Runnable() {41public void run() {42createAndShowGUI();43}44});4546Robot robot = new Robot();47robot.setAutoDelay(50);48robot.waitForIdle();4950Util.hitMnemonics(robot, KeyEvent.VK_F);51Util.hitKeys(robot, KeyEvent.VK_C);5253robot.waitForIdle();54Thread.sleep(1000);5556if (!closeActivated || customActivated) {57throw new RuntimeException("Didn't pass the muster");58}59}60public static void createAndShowGUI() {61JMenuBar menubar = new JMenuBar();6263JMenu fileMenu = new JMenu("File");64fileMenu.setMnemonic('f');6566JMenuItem fmi1 = new JMenuItem();67fmi1 = new JMenuItem("Open");68JMenuItem fmi2 = new JMenuItem();69fmi2 = new JMenuItem("Close");70fmi2.setMnemonic('c');71fmi2.addActionListener(new ActionListener() {72public void actionPerformed(ActionEvent e) {73closeActivated = true;74}75});7677fileMenu.add( fmi1);78fileMenu.add( fmi2);7980menubar.add( fileMenu);8182JMenu custom = new JMenu("Custom");83custom.setMnemonic('c');84JMenuItem cmi = new JMenuItem();85cmi = new JMenuItem("Properties");86cmi.setMnemonic('p');87custom.add( cmi);88custom.addMenuListener(new MenuListener() {89public void menuSelected(MenuEvent e) {90customActivated = true;91}92public void menuDeselected(MenuEvent e) {}93public void menuCanceled(MenuEvent e) {}94});95menubar.add( custom);9697JFrame frame = new JFrame();98frame.setJMenuBar( menubar);99frame.setSize(300, 300);100frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);101frame.pack();102frame.setVisible(true);103}104}105106107