Path: blob/master/test/jdk/javax/swing/JMenuItem/4171437/bug4171437.java
41153 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*/2223/*24* @test25* @key headful26* @bug 417143727* @library ../../regtesthelpers28* @build Util29* @author Georges Saab30* @run main bug417143731*/3233import java.awt.*;34import java.awt.event.*;35import java.util.ArrayList;36import javax.swing.*;37import javax.swing.event.*;3839public class bug4171437 {40static volatile boolean closeActivated = false;41static volatile boolean customActivated = false;42static JFrame frame;4344public static void main(String[] args) throws Exception {45try {46Robot robot = new Robot();47robot.setAutoDelay(100);48SwingUtilities.invokeAndWait(new Runnable() {49public void run() {50createAndShowGUI();51}52});5354robot.waitForIdle();55robot.delay(1000);5657Util.hitMnemonics(robot, KeyEvent.VK_F);58Util.hitKeys(robot, KeyEvent.VK_C);5960robot.waitForIdle();6162if (!closeActivated || customActivated) {63throw new RuntimeException("Didn't pass the muster");64}65} finally {66if (frame != null) SwingUtilities.invokeAndWait(() -> frame.dispose());67}68}69public static void createAndShowGUI() {70JMenuBar menubar = new JMenuBar();7172JMenu fileMenu = new JMenu("File");73fileMenu.setMnemonic('f');7475JMenuItem fmi1 = new JMenuItem();76fmi1 = new JMenuItem("Open");77JMenuItem fmi2 = new JMenuItem();78fmi2 = new JMenuItem("Close");79fmi2.setMnemonic('c');80fmi2.addActionListener(new ActionListener() {81public void actionPerformed(ActionEvent e) {82closeActivated = true;83}84});8586fileMenu.add( fmi1);87fileMenu.add( fmi2);8889menubar.add( fileMenu);9091JMenu custom = new JMenu("Custom");92custom.setMnemonic('c');93JMenuItem cmi = new JMenuItem();94cmi = new JMenuItem("Properties");95cmi.setMnemonic('p');96custom.add( cmi);97custom.addMenuListener(new MenuListener() {98public void menuSelected(MenuEvent e) {99customActivated = true;100}101public void menuDeselected(MenuEvent e) {}102public void menuCanceled(MenuEvent e) {}103});104menubar.add( custom);105106frame = new JFrame();107frame.setJMenuBar( menubar);108frame.setSize(300, 300);109frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);110frame.pack();111frame.setLocationRelativeTo(null);112frame.setVisible(true);113}114}115116117