Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/swing/JMenuItem/6249972/bug6249972.java
38853 views
/*1* Copyright (c) 2006, 2014, 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 624997224@summary Tests that JMenuItem(String,int) handles lower-case mnemonics properly.25@library ../../../../lib/testlibrary26@build ExtendedRobot27@author Mikhail Lapshin28@run main bug624997229*/3031import javax.swing.*;32import java.awt.event.ActionListener;33import java.awt.event.ActionEvent;34import java.awt.event.KeyEvent;3536public class bug6249972 implements ActionListener {373839private JFrame frame;40private JMenu menu;41private volatile boolean testPassed = false;4243public static void main(String[] args) throws Exception {44bug6249972 bugTest = new bug6249972();45bugTest.test();46}4748public bug6249972() throws Exception {49SwingUtilities.invokeAndWait(50new Runnable() {51public void run() {52frame = new JFrame("bug6249972");53frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);5455JMenuBar bar = new JMenuBar();56frame.setJMenuBar(bar);5758menu = new JMenu("Problem");59bar.add(menu);6061JMenuItem item = new JMenuItem("JMenuItem(String,'z')", 'z');62item.addActionListener(bug6249972.this);63menu.add(item);6465frame.setLocationRelativeTo(null);66frame.pack();67frame.setVisible(true);68}69}70);71}727374private void test() throws Exception {75ExtendedRobot robot = new ExtendedRobot();76robot.waitForIdle();77java.awt.Point p = menu.getLocationOnScreen();78java.awt.Dimension size = menu.getSize();79p.x += size.width / 2;80p.y += size.height / 2;81robot.mouseMove(p.x, p.y);82robot.click();83robot.delay(100);8485robot.waitForIdle();86robot.type(KeyEvent.VK_Z);8788robot.waitForIdle();89frame.dispose(); // Try to stop the event dispatch thread9091if (!testPassed) {92throw new RuntimeException("JMenuItem(String,int) does not handle " +93"lower-case mnemonics properly.");94}9596System.out.println("Test passed");97}9899public void actionPerformed(ActionEvent e) {100// We are in the actionPerformed() method -101// JMenuItem(String,int) handles lower-case mnemonics properly102testPassed = true;103}104}105106107