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