1
1
/*
2
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
2
+ * Copyright (c) 2013, 2021, Oracle and/or its affiliates. All rights reserved.
3
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
4
*
5
5
* This code is free software; you can redistribute it and/or modify it
21
21
* questions.
22
22
*/
23
23
24
- import java .awt .*;
25
- import java .awt .event .*;
26
- import javax .swing .*;
24
+ import java .awt .Robot ;
25
+ import java .awt .event .ActionEvent ;
26
+ import java .awt .event .ActionListener ;
27
+ import java .awt .event .KeyEvent ;
28
+ import javax .swing .JFrame ;
29
+ import javax .swing .JMenu ;
30
+ import javax .swing .JMenuBar ;
31
+ import javax .swing .JMenuItem ;
32
+ import javax .swing .SwingUtilities ;
27
33
28
34
/**
29
35
* @test
37
43
*/
38
44
public class bug4515762 {
39
45
40
- private static volatile boolean actionExpected = false ;
41
- private static volatile boolean actionRecieved = false ;
46
+ private static volatile boolean actionExpected ;
47
+ private static volatile boolean actionRecieved ;
42
48
private static JFrame frame ;
43
49
44
50
/**
@@ -99,18 +105,18 @@ public void actionPerformed(ActionEvent evt) {
99
105
return menuItem ;
100
106
}
101
107
102
- public static void checkAction () {
108
+ public static void checkAction (String str ) {
103
109
if (actionRecieved == true ) {
104
110
actionRecieved = false ;
105
111
} else {
106
- throw new RuntimeException ("Action has not been received" );
112
+ throw new RuntimeException ("Action has not been received: " + str );
107
113
}
108
114
}
109
115
110
116
public static void main (String [] args ) throws Throwable {
111
117
try {
112
118
Robot robot = new Robot ();
113
- robot .setAutoDelay (250 );
119
+ robot .setAutoDelay (100 );
114
120
115
121
SwingUtilities .invokeAndWait (new Runnable () {
116
122
@@ -119,21 +125,25 @@ public void run() {
119
125
frame = new JFrame ("Test" );
120
126
frame .setJMenuBar (createMenuBar ());
121
127
frame .setDefaultCloseOperation (JFrame .EXIT_ON_CLOSE );
128
+ frame .setLocationRelativeTo (null );
122
129
frame .pack ();
123
130
frame .setVisible (true );
124
131
frame .toFront ();
125
132
}
126
133
});
127
134
128
135
robot .waitForIdle ();
136
+ robot .delay (1000 );
129
137
130
138
Util .hitMnemonics (robot , KeyEvent .VK_D );
131
139
robot .waitForIdle ();
132
140
133
141
// Press the S key many times (should not cause an action peformed)
134
142
int TIMES = 5 ;
135
143
for (int i = 0 ; i < TIMES ; i ++) {
136
- Util .hitKeys (robot , KeyEvent .VK_S );
144
+ robot .keyPress (KeyEvent .VK_S );
145
+ robot .keyRelease (KeyEvent .VK_S );
146
+ robot .waitForIdle ();
137
147
}
138
148
robot .waitForIdle ();
139
149
@@ -146,7 +156,7 @@ public void run() {
146
156
robot .keyRelease (KeyEvent .VK_S );
147
157
robot .waitForIdle ();
148
158
149
- checkAction ();
159
+ checkAction ("pressing VK_S" );
150
160
151
161
Util .hitMnemonics (robot , KeyEvent .VK_U );
152
162
robot .waitForIdle ();
@@ -155,28 +165,31 @@ public void run() {
155
165
robot .keyRelease (KeyEvent .VK_M );
156
166
robot .waitForIdle ();
157
167
158
- checkAction ();
168
+ checkAction ("pressing VK_M" );
159
169
160
170
Util .hitMnemonics (robot , KeyEvent .VK_U );
161
171
robot .waitForIdle ();
162
- Util .hitKeys (robot , KeyEvent .VK_T );
172
+ robot .keyPress (KeyEvent .VK_T );
173
+ robot .keyRelease (KeyEvent .VK_T );
163
174
robot .waitForIdle ();
164
175
165
- checkAction ();
176
+ checkAction ("pressing VK_T" );
166
177
167
178
Util .hitMnemonics (robot , KeyEvent .VK_U );
168
179
robot .waitForIdle ();
169
- Util .hitKeys (robot , KeyEvent .VK_W );
180
+ robot .keyPress (KeyEvent .VK_W );
181
+ robot .keyRelease (KeyEvent .VK_W );
170
182
robot .waitForIdle ();
171
183
172
- checkAction ();
184
+ checkAction ("pressing VK_W" );
173
185
174
186
Util .hitMnemonics (robot , KeyEvent .VK_U );
175
187
robot .waitForIdle ();
176
- Util .hitKeys (robot , KeyEvent .VK_U );
188
+ robot .keyPress (KeyEvent .VK_U );
189
+ robot .keyRelease (KeyEvent .VK_U );
177
190
robot .waitForIdle ();
178
191
179
- checkAction ();
192
+ checkAction ("pressing VK_U" );
180
193
} finally {
181
194
if (frame != null ) SwingUtilities .invokeAndWait (() -> frame .dispose ());
182
195
}
1 commit comments
openjdk-notifier[bot] commentedon Oct 30, 2022
Review
Issues