Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/javax/swing/JMenuItem/4171437/bug4171437.java
41153 views
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
24
/*
25
* @test
26
* @key headful
27
* @bug 4171437
28
* @library ../../regtesthelpers
29
* @build Util
30
* @author Georges Saab
31
* @run main bug4171437
32
*/
33
34
import java.awt.*;
35
import java.awt.event.*;
36
import java.util.ArrayList;
37
import javax.swing.*;
38
import javax.swing.event.*;
39
40
public class bug4171437 {
41
static volatile boolean closeActivated = false;
42
static volatile boolean customActivated = false;
43
static JFrame frame;
44
45
public static void main(String[] args) throws Exception {
46
try {
47
Robot robot = new Robot();
48
robot.setAutoDelay(100);
49
SwingUtilities.invokeAndWait(new Runnable() {
50
public void run() {
51
createAndShowGUI();
52
}
53
});
54
55
robot.waitForIdle();
56
robot.delay(1000);
57
58
Util.hitMnemonics(robot, KeyEvent.VK_F);
59
Util.hitKeys(robot, KeyEvent.VK_C);
60
61
robot.waitForIdle();
62
63
if (!closeActivated || customActivated) {
64
throw new RuntimeException("Didn't pass the muster");
65
}
66
} finally {
67
if (frame != null) SwingUtilities.invokeAndWait(() -> frame.dispose());
68
}
69
}
70
public static void createAndShowGUI() {
71
JMenuBar menubar = new JMenuBar();
72
73
JMenu fileMenu = new JMenu("File");
74
fileMenu.setMnemonic('f');
75
76
JMenuItem fmi1 = new JMenuItem();
77
fmi1 = new JMenuItem("Open");
78
JMenuItem fmi2 = new JMenuItem();
79
fmi2 = new JMenuItem("Close");
80
fmi2.setMnemonic('c');
81
fmi2.addActionListener(new ActionListener() {
82
public void actionPerformed(ActionEvent e) {
83
closeActivated = true;
84
}
85
});
86
87
fileMenu.add( fmi1);
88
fileMenu.add( fmi2);
89
90
menubar.add( fileMenu);
91
92
JMenu custom = new JMenu("Custom");
93
custom.setMnemonic('c');
94
JMenuItem cmi = new JMenuItem();
95
cmi = new JMenuItem("Properties");
96
cmi.setMnemonic('p');
97
custom.add( cmi);
98
custom.addMenuListener(new MenuListener() {
99
public void menuSelected(MenuEvent e) {
100
customActivated = true;
101
}
102
public void menuDeselected(MenuEvent e) {}
103
public void menuCanceled(MenuEvent e) {}
104
});
105
menubar.add( custom);
106
107
frame = new JFrame();
108
frame.setJMenuBar( menubar);
109
frame.setSize(300, 300);
110
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
111
frame.pack();
112
frame.setLocationRelativeTo(null);
113
frame.setVisible(true);
114
}
115
}
116
117