Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/swing/JMenuItem/4171437/bug4171437.java
38854 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
/* @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
36
public class bug4171437 {
37
static volatile boolean closeActivated = false;
38
static volatile boolean customActivated = false;
39
40
public static void main(String[] args) throws Exception {
41
SwingUtilities.invokeAndWait(new Runnable() {
42
public void run() {
43
createAndShowGUI();
44
}
45
});
46
47
Robot robot = new Robot();
48
robot.setAutoDelay(50);
49
robot.waitForIdle();
50
51
Util.hitMnemonics(robot, KeyEvent.VK_F);
52
Util.hitKeys(robot, KeyEvent.VK_C);
53
54
robot.waitForIdle();
55
Thread.sleep(1000);
56
57
if (!closeActivated || customActivated) {
58
throw new RuntimeException("Didn't pass the muster");
59
}
60
}
61
public static void createAndShowGUI() {
62
JMenuBar menubar = new JMenuBar();
63
64
JMenu fileMenu = new JMenu("File");
65
fileMenu.setMnemonic('f');
66
67
JMenuItem fmi1 = new JMenuItem();
68
fmi1 = new JMenuItem("Open");
69
JMenuItem fmi2 = new JMenuItem();
70
fmi2 = new JMenuItem("Close");
71
fmi2.setMnemonic('c');
72
fmi2.addActionListener(new ActionListener() {
73
public void actionPerformed(ActionEvent e) {
74
closeActivated = true;
75
}
76
});
77
78
fileMenu.add( fmi1);
79
fileMenu.add( fmi2);
80
81
menubar.add( fileMenu);
82
83
JMenu custom = new JMenu("Custom");
84
custom.setMnemonic('c');
85
JMenuItem cmi = new JMenuItem();
86
cmi = new JMenuItem("Properties");
87
cmi.setMnemonic('p');
88
custom.add( cmi);
89
custom.addMenuListener(new MenuListener() {
90
public void menuSelected(MenuEvent e) {
91
customActivated = true;
92
}
93
public void menuDeselected(MenuEvent e) {}
94
public void menuCanceled(MenuEvent e) {}
95
});
96
menubar.add( custom);
97
98
JFrame frame = new JFrame();
99
frame.setJMenuBar( menubar);
100
frame.setSize(300, 300);
101
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
102
frame.pack();
103
frame.setVisible(true);
104
}
105
}
106
107