Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/javax/swing/JMenuItem/6249972/bug6249972.java
41153 views
1
/*
2
* Copyright (c) 2006, 2014, 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
24
/*
25
* @test
26
* @key headful
27
* @bug 6249972
28
* @summary Tests that JMenuItem(String,int) handles lower-case mnemonics properly.
29
* @author Mikhail Lapshin
30
* @run main bug6249972
31
*/
32
33
import javax.swing.*;
34
import java.awt.event.ActionListener;
35
import java.awt.event.ActionEvent;
36
import java.awt.event.KeyEvent;
37
import java.awt.event.InputEvent;
38
import java.awt.Dimension;
39
import java.awt.Point;
40
import java.awt.Robot;
41
42
public class bug6249972 implements ActionListener {
43
44
private static JFrame frame;
45
private static Robot robot;
46
private JMenu menu;
47
private volatile boolean testPassed = false;
48
private volatile Point p = null;
49
private volatile Dimension size = null;
50
51
public static void main(String[] args) throws Exception {
52
try {
53
robot = new Robot();
54
robot.setAutoDelay(100);
55
bug6249972 bugTest = new bug6249972();
56
robot.waitForIdle();
57
robot.delay(1000);
58
bugTest.test();
59
} finally {
60
if (frame != null) {
61
SwingUtilities.invokeAndWait(() -> frame.dispose());
62
}
63
}
64
}
65
66
public bug6249972() throws Exception {
67
SwingUtilities.invokeAndWait(() -> {
68
frame = new JFrame("bug6249972");
69
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
70
71
JMenuBar bar = new JMenuBar();
72
frame.setJMenuBar(bar);
73
74
menu = new JMenu("Problem");
75
bar.add(menu);
76
77
JMenuItem item = new JMenuItem("JMenuItem(String,'z')", 'z');
78
item.addActionListener(bug6249972.this);
79
menu.add(item);
80
81
frame.setLocationRelativeTo(null);
82
frame.pack();
83
frame.setVisible(true);
84
});
85
}
86
87
88
private void test() throws Exception {
89
SwingUtilities.invokeAndWait(() -> {
90
p = menu.getLocationOnScreen();
91
size = menu.getSize();
92
});
93
p.x += size.width / 2;
94
p.y += size.height / 2;
95
robot.mouseMove(p.x, p.y);
96
robot.waitForIdle();
97
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
98
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
99
100
robot.waitForIdle();
101
robot.delay(100);
102
robot.keyPress(KeyEvent.VK_Z);
103
robot.keyRelease(KeyEvent.VK_Z);
104
105
robot.waitForIdle();
106
robot.delay(1000);
107
108
if (!testPassed) {
109
throw new RuntimeException("JMenuItem(String,int) does not handle " +
110
"lower-case mnemonics properly.");
111
}
112
113
System.out.println("Test passed");
114
}
115
116
public void actionPerformed(ActionEvent e) {
117
// We are in the actionPerformed() method -
118
// JMenuItem(String,int) handles lower-case mnemonics properly
119
testPassed = true;
120
}
121
}
122
123