1 /* 2 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 /* @test 24 @bug 4171437 25 @library ../../regtesthelpers 26 @build Util 27 @author Georges Saab 28 @run main bug4171437 29 */ 30 import java.awt.*; 31 import java.awt.event.*; 32 import java.util.ArrayList; 33 import javax.swing.*; 34 import javax.swing.event.*; 35 import sun.awt.SunToolkit; 36 37 public class bug4171437 { 38 static volatile boolean closeActivated = false; 39 static volatile boolean customActivated = false; 40 41 public static void main(String[] args) throws Exception { 42 SwingUtilities.invokeAndWait(new Runnable() { 43 public void run() { 44 createAndShowGUI(); 45 } 46 }); 47 48 SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); 49 toolkit.realSync(); 50 51 Robot robot = new Robot(); 52 robot.setAutoDelay(50); 53 54 Util.hitMnemonics(robot, KeyEvent.VK_F); 55 Util.hitKeys(robot, KeyEvent.VK_C); 56 57 toolkit.realSync(); 58 Thread.sleep(1000); 59 60 if (!closeActivated || customActivated) { 61 throw new RuntimeException("Didn't pass the muster"); 62 } 63 } 64 public static void createAndShowGUI() { 65 JMenuBar menubar = new JMenuBar(); 66 67 JMenu fileMenu = new JMenu("File"); 68 fileMenu.setMnemonic('f'); 69 70 JMenuItem fmi1 = new JMenuItem(); 71 fmi1 = new JMenuItem("Open"); 72 JMenuItem fmi2 = new JMenuItem(); 73 fmi2 = new JMenuItem("Close"); 74 fmi2.setMnemonic('c'); 75 fmi2.addActionListener(new ActionListener() { 76 public void actionPerformed(ActionEvent e) { 77 closeActivated = true; 78 } 79 }); 80 81 fileMenu.add( fmi1); 82 fileMenu.add( fmi2); 83 84 menubar.add( fileMenu); 85 86 JMenu custom = new JMenu("Custom"); 87 custom.setMnemonic('c'); 88 JMenuItem cmi = new JMenuItem(); 89 cmi = new JMenuItem("Properties"); 90 cmi.setMnemonic('p'); 91 custom.add( cmi); 92 custom.addMenuListener(new MenuListener() { 93 public void menuSelected(MenuEvent e) { 94 customActivated = true; 95 } 96 public void menuDeselected(MenuEvent e) {} 97 public void menuCanceled(MenuEvent e) {} 98 }); 99 menubar.add( custom); 100 101 JFrame frame = new JFrame(); 102 frame.setJMenuBar( menubar); 103 frame.setSize(300, 300); 104 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 105 frame.pack(); 106 frame.setVisible(true); 107 } 108 }