Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/awt/Focus/8073453/AWTFocusTransitionTest.java
41153 views
1
/*
2
* Copyright (c) 2015, 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 8073453
28
* @summary Focus doesn't move when pressing Shift + Tab keys
29
* @compile AWTFocusTransitionTest.java
30
* @run main/othervm AWTFocusTransitionTest
31
*/
32
33
import java.awt.Button;
34
import java.awt.Component;
35
import java.awt.DefaultFocusTraversalPolicy;
36
import java.awt.Frame;
37
import java.awt.GridLayout;
38
import java.awt.Panel;
39
import java.awt.Robot;
40
import java.awt.TextField;
41
import java.awt.event.KeyEvent;
42
43
public class AWTFocusTransitionTest {
44
private static Robot robot;
45
46
private static Frame frame;
47
private static TextField textField;
48
private static Button button;
49
50
public static void main(String[] args) throws Exception {
51
robot = new Robot();
52
robot.setAutoDelay(100);
53
54
try {
55
createAndShowGUI();
56
57
robot.waitForIdle();
58
59
checkFocusOwner(textField);
60
61
robot.keyPress(KeyEvent.VK_TAB);
62
robot.keyRelease(KeyEvent.VK_TAB);
63
robot.waitForIdle();
64
65
checkFocusOwner(button);
66
67
robot.keyPress(KeyEvent.VK_SHIFT);
68
robot.keyPress(KeyEvent.VK_TAB);
69
robot.keyRelease(KeyEvent.VK_TAB);
70
robot.keyRelease(KeyEvent.VK_SHIFT);
71
robot.waitForIdle();
72
73
checkFocusOwner(textField);
74
75
robot.keyPress(KeyEvent.VK_SHIFT);
76
robot.keyPress(KeyEvent.VK_TAB);
77
robot.keyRelease(KeyEvent.VK_TAB);
78
robot.keyRelease(KeyEvent.VK_SHIFT);
79
robot.waitForIdle();
80
81
checkFocusOwner(button);
82
} finally {
83
if (frame != null) {
84
frame.dispose();
85
}
86
}
87
System.out.println("Test Passed!");
88
}
89
90
private static void createAndShowGUI() {
91
frame = new Frame("AWTFocusTransitionTest");
92
frame.setSize(300, 300);
93
frame.setFocusTraversalPolicyProvider(true);
94
frame.setFocusTraversalPolicy(new DefaultFocusTraversalPolicy());
95
96
textField = new TextField();
97
button = new Button();
98
99
Panel panel = new Panel();
100
panel.setFocusTraversalPolicyProvider(true);
101
panel.setFocusTraversalPolicy(new DefaultFocusTraversalPolicy());
102
103
Panel p = new Panel();
104
p.setLayout(new GridLayout(3, 1));
105
p.add(textField);
106
p.add(button);
107
p.add(panel);
108
109
frame.add(p);
110
frame.setLocationRelativeTo(null);
111
frame.setVisible(true);
112
}
113
114
private static void checkFocusOwner(Component component) {
115
if (component != frame.getFocusOwner()) {
116
throw new RuntimeException("Test Failed! Incorrect focus " +
117
"owner: " + frame.getFocusOwner() +
118
", but expected: " + component);
119
}
120
}
121
}
122
123