Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/awt/Choice/GrabLockTest/GrabLockTest.java
41152 views
1
/*
2
* Copyright (c) 2003, 2016, 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
@test
25
@key headful
26
@bug 4800638
27
@summary Tests that Choice does not lock the Desktop
28
@run main GrabLockTest
29
*/
30
import java.awt.*;
31
import java.awt.event.*;
32
33
public class GrabLockTest
34
{
35
public static void main (String args[])
36
{
37
Frame frame = new TestFrame();
38
}
39
}
40
41
class TestFrame extends Frame implements MouseListener {
42
public TestFrame() {
43
Choice choice = new Choice();
44
choice.addItem("Fist Item");
45
choice.addItem("Second Item");
46
add(choice,BorderLayout.NORTH);
47
Panel panel = new Panel();
48
panel.addMouseListener(this);
49
panel.setBackground(Color.RED);
50
add(panel);
51
setSize(200, 200);
52
setVisible(true);
53
toFront();
54
55
try {
56
Robot robot = new Robot();
57
robot.setAutoWaitForIdle(true);
58
robot.setAutoDelay(50);
59
60
robot.waitForIdle();
61
62
Point pt = choice.getLocationOnScreen();
63
robot.mouseMove(pt.x + choice.getWidth() - choice.getHeight()/2,
64
pt.y + choice.getHeight()/2);
65
robot.mousePress(InputEvent.BUTTON1_MASK);
66
robot.waitForIdle();
67
robot.mouseMove(pt.x + choice.getWidth()/2,
68
pt.y + choice.getHeight()*2);
69
robot.waitForIdle();
70
robot.mousePress(InputEvent.BUTTON2_MASK);
71
robot.waitForIdle();
72
Point pt1 = panel.getLocationOnScreen();
73
robot.mouseMove(pt1.x + panel.getWidth()/2,
74
pt1.y + panel.getHeight()/2);
75
robot.waitForIdle();
76
robot.mouseRelease(InputEvent.BUTTON1_MASK);
77
robot.mouseRelease(InputEvent.BUTTON2_MASK);
78
79
robot.waitForIdle();
80
81
robot.mousePress(InputEvent.BUTTON1_MASK);
82
robot.delay(30);
83
robot.mouseRelease(InputEvent.BUTTON1_MASK);
84
robot.waitForIdle();
85
if (nPressed == 0) {
86
robot.keyPress(KeyEvent.VK_ESCAPE);
87
robot.keyRelease(KeyEvent.VK_ESCAPE);
88
throw new RuntimeException("GrabLockTest failed." + nPressed);
89
}
90
} catch (Exception e) {
91
throw new RuntimeException("The test was not completed.\n\n" + e);
92
}
93
94
}
95
96
public int nPressed = 0;
97
98
public void mouseClicked(MouseEvent e) {
99
}
100
101
public void mousePressed(MouseEvent e) {
102
nPressed++;
103
System.out.println("Pressed!");
104
}
105
106
public void mouseReleased(MouseEvent e) {
107
}
108
109
public void mouseEntered(MouseEvent e) {}
110
public void mouseExited(MouseEvent e) {}
111
}// class TestFrame
112
113