Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/awt/Mouse/EnterExitEvents/ResizingFrameTest.java
47311 views
1
/*
2
* Copyright (c) 2005, 2006, 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
* @bug 7154048
27
* @summary Programmatically resized window does not receive mouse entered/exited events
28
* @author alexandr.scherbatiy area=awt.event
29
* @run main ResizingFrameTest
30
*/
31
32
import java.awt.*;
33
import java.awt.event.*;
34
import javax.swing.*;
35
36
public class ResizingFrameTest {
37
38
private static volatile int mouseEnteredCount = 0;
39
private static volatile int mouseExitedCount = 0;
40
private static JFrame frame;
41
42
public static void main(String[] args) throws Exception {
43
44
Robot robot = new Robot();
45
robot.setAutoDelay(50);
46
robot.mouseMove(100, 100);
47
robot.delay(200);
48
49
// create a frame under the mouse cursor
50
SwingUtilities.invokeAndWait(new Runnable() {
51
52
@Override
53
public void run() {
54
createAndShowGUI();
55
}
56
});
57
58
59
robot.waitForIdle();
60
robot.delay(1000);
61
62
if (mouseEnteredCount != 1 || mouseExitedCount != 0) {
63
throw new RuntimeException("No Mouse Entered/Exited events!");
64
}
65
66
// iconify frame
67
SwingUtilities.invokeAndWait(new Runnable() {
68
69
@Override
70
public void run() {
71
frame.setExtendedState(Frame.ICONIFIED);
72
}
73
});
74
75
robot.waitForIdle();
76
robot.delay(1000);
77
78
if (mouseEnteredCount != 1 || mouseExitedCount != 1) {
79
throw new RuntimeException("No Mouse Entered/Exited events! "+mouseEnteredCount+", "+mouseExitedCount);
80
}
81
82
// deiconify frame
83
SwingUtilities.invokeAndWait(new Runnable() {
84
85
@Override
86
public void run() {
87
frame.setExtendedState(Frame.NORMAL);
88
}
89
});
90
91
robot.waitForIdle();
92
robot.delay(1000);
93
94
if (mouseEnteredCount != 2 || mouseExitedCount != 1) {
95
throw new RuntimeException("No Mouse Entered/Exited events!");
96
}
97
98
// move the mouse out of the frame
99
robot.mouseMove(500, 500);
100
robot.waitForIdle();
101
robot.delay(1000);
102
103
if (mouseEnteredCount != 2 || mouseExitedCount != 2) {
104
throw new RuntimeException("No Mouse Entered/Exited events!");
105
}
106
107
// maximize the frame
108
SwingUtilities.invokeAndWait(new Runnable() {
109
110
@Override
111
public void run() {
112
frame.setExtendedState(Frame.MAXIMIZED_BOTH);
113
}
114
});
115
116
robot.waitForIdle();
117
robot.delay(1000);
118
119
if (mouseEnteredCount != 3 || mouseExitedCount != 2) {
120
throw new RuntimeException("No Mouse Entered/Exited events!");
121
}
122
123
124
// demaximize the frame
125
SwingUtilities.invokeAndWait(new Runnable() {
126
127
@Override
128
public void run() {
129
frame.setExtendedState(Frame.NORMAL);
130
}
131
});
132
133
robot.waitForIdle();
134
robot.delay(1000);
135
136
if (mouseEnteredCount != 3 || mouseExitedCount != 3) {
137
throw new RuntimeException("No Mouse Entered/Exited events!");
138
139
}
140
141
// move the frame under the mouse
142
SwingUtilities.invokeAndWait(new Runnable() {
143
144
@Override
145
public void run() {
146
frame.setLocation(400, 400);
147
}
148
});
149
150
robot.waitForIdle();
151
robot.delay(1000);
152
153
if (mouseEnteredCount != 4 || mouseExitedCount != 3) {
154
throw new RuntimeException("No Mouse Entered/Exited events!");
155
}
156
157
// move the frame out of the mouse
158
SwingUtilities.invokeAndWait(new Runnable() {
159
160
@Override
161
public void run() {
162
frame.setLocation(100, 100);
163
}
164
});
165
166
robot.waitForIdle();
167
robot.delay(400);
168
169
if (mouseEnteredCount != 4 || mouseExitedCount != 4) {
170
throw new RuntimeException("No Mouse Entered/Exited events!");
171
}
172
173
// enlarge the frame bounds
174
SwingUtilities.invokeAndWait(new Runnable() {
175
176
@Override
177
public void run() {
178
frame.setBounds(100, 100, 800, 800);
179
}
180
});
181
182
robot.waitForIdle();
183
robot.delay(200);
184
185
if (mouseEnteredCount != 5 || mouseExitedCount != 4) {
186
throw new RuntimeException("No Mouse Entered/Exited events!");
187
}
188
189
// make the frame bounds smaller
190
SwingUtilities.invokeAndWait(new Runnable() {
191
192
@Override
193
public void run() {
194
frame.setBounds(100, 100, 200, 300);
195
}
196
});
197
198
robot.waitForIdle();
199
robot.delay(400);
200
201
202
if (mouseEnteredCount != 5 || mouseExitedCount != 5) {
203
throw new RuntimeException("No Mouse Entered/Exited events!");
204
}
205
}
206
207
private static void createAndShowGUI() {
208
209
frame = new JFrame("Main Frame");
210
frame.setSize(300, 200);
211
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
212
213
frame.addMouseListener(new MouseAdapter() {
214
215
@Override
216
public void mouseEntered(MouseEvent e) {
217
mouseEnteredCount++;
218
}
219
220
@Override
221
public void mouseExited(MouseEvent e) {
222
mouseExitedCount++;
223
}
224
});
225
226
frame.setVisible(true);
227
}
228
}
229
230