Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/awt/Mouse/GetMousePositionTest/GetMousePositionWithOverlay.java
41153 views
1
/*
2
* Copyright (c) 2013, 2018, 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
import java.awt.Frame;
25
import java.awt.Point;
26
import java.awt.Robot;
27
import java.awt.Rectangle;
28
29
/*
30
* @test
31
* @key headful
32
* @bug 8012026 8196435
33
* @summary Component.getMousePosition() does not work in an applet on MacOS
34
* @run main GetMousePositionWithOverlay
35
*/
36
37
public class GetMousePositionWithOverlay {
38
39
private static Frame backFrame;
40
private static Frame frontFrame;
41
private static Robot robot;
42
43
public static void main(String[] args) throws Throwable {
44
robot = new Robot();
45
46
try{
47
constructTestUI();
48
} catch (Exception e) {
49
dispose();
50
throw new RuntimeException("Unexpected Exception!");
51
}
52
53
robot.waitForIdle();
54
55
doTest();
56
dispose();
57
}
58
59
private static void doTest() {
60
61
frontFrame.toFront();
62
robot.waitForIdle();
63
64
Rectangle bounds = new Rectangle(frontFrame.getLocationOnScreen(), frontFrame.getSize());
65
robot.mouseMove(bounds.x + bounds.width / 2, bounds.y + bounds.height / 2);
66
robot.waitForIdle();
67
68
Point pos = backFrame.getMousePosition();
69
if (pos != null) {
70
dispose();
71
throw new RuntimeException("Test failed. Mouse position should be null but was " + pos);
72
}
73
74
pos = frontFrame.getMousePosition();
75
if (pos == null) {
76
dispose();
77
throw new RuntimeException("Test failed. Mouse position should not be null");
78
}
79
80
robot.mouseMove(189, 189);
81
robot.waitForIdle();
82
83
pos = backFrame.getMousePosition();
84
if (pos == null) {
85
dispose();
86
throw new RuntimeException("Test failed. Mouse position should not be null");
87
}
88
89
}
90
91
private static void dispose() {
92
93
if (backFrame != null) {
94
backFrame.dispose();
95
}
96
97
if (frontFrame != null) {
98
frontFrame.dispose();
99
}
100
}
101
102
private static void constructTestUI() {
103
backFrame = new Frame();
104
backFrame.setBounds(100, 100, 100, 100);
105
backFrame.setResizable(false);
106
backFrame.setVisible(true);
107
108
frontFrame = new Frame();
109
frontFrame.setBounds(120, 120, 60, 60);
110
frontFrame.setResizable(false);
111
frontFrame.setVisible(true);
112
113
}
114
}
115
116
117