Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/jdk17u
Path: blob/master/test/jdk/java/awt/Focus/DeiconifiedFrameLoosesFocus/DeiconifiedFrameLoosesFocus.java
66645 views
1
/*
2
* Copyright (c) 2006, 2021, 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 6480534
28
@summary A Frame changing its state from ICONIFIED to NORMAL should regain focus.
29
@library ../../regtesthelpers
30
@build Util
31
@run main DeiconifiedFrameLoosesFocus
32
*/
33
34
import java.awt.Frame;
35
import java.awt.Robot;
36
import java.awt.Toolkit;
37
import test.java.awt.regtesthelpers.Util;
38
39
public class DeiconifiedFrameLoosesFocus {
40
Robot robot;
41
static final Frame frame = new Frame("Frame");
42
43
public static void main(String[] args) {
44
DeiconifiedFrameLoosesFocus app = new DeiconifiedFrameLoosesFocus();
45
app.init();
46
try {
47
app.start();
48
} finally {
49
frame.dispose();
50
}
51
}
52
53
public void init() {
54
robot = Util.createRobot();
55
}
56
57
public void start() {
58
if (!Toolkit.getDefaultToolkit().isFrameStateSupported(Frame.ICONIFIED) ||
59
!Toolkit.getDefaultToolkit().isFrameStateSupported(Frame.NORMAL))
60
{
61
System.out.println("Frame.ICONIFIED or Frame.NORMAL state is unsupported.");
62
return;
63
}
64
65
frame.setSize(100, 100);
66
67
frame.setVisible(true);
68
69
Util.waitForIdle(robot);
70
robot.delay(1000);
71
72
if (!frame.isFocused()) {
73
Util.clickOnTitle(frame, robot);
74
Util.waitForIdle(robot);
75
}
76
77
if (!frame.isFocused()) {
78
throw new Error("Test error: couldn't focus the Frame.");
79
}
80
81
test();
82
System.out.println("Test passed.");
83
}
84
85
void test() {
86
frame.setExtendedState(Frame.ICONIFIED);
87
88
Util.waitForIdle(robot);
89
robot.delay(500);
90
91
frame.setExtendedState(Frame.NORMAL);
92
93
Util.waitForIdle(robot);
94
robot.delay(500);
95
96
if (!frame.isFocused()) {
97
throw new TestFailedException("the Frame didn't regain focus after restoring!");
98
}
99
}
100
}
101
102
class TestFailedException extends RuntimeException {
103
TestFailedException(String msg) {
104
super("Test failed: " + msg);
105
}
106
}
107
108