Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/awt/Component/Revalidate/Revalidate.java
41153 views
1
/*
2
* Copyright (c) 2011, 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 7036669
28
@summary Test Component.revalidate() method
29
@author [email protected]: area=awt.component
30
@run main/othervm -Djava.awt.smartInvalidate=true Revalidate
31
*/
32
33
import java.awt.*;
34
35
public class Revalidate {
36
private static Frame frame = new Frame();
37
private static Panel panel = new Panel() {
38
@Override
39
public boolean isValidateRoot() {
40
return true;
41
}
42
};
43
private static Button button = new Button("Test");
44
45
private static void sleep() {
46
try { Thread.sleep(500); } catch (Exception e) {}
47
}
48
49
private static void printState(String str) {
50
System.out.println(str + " isValid state: ");
51
System.out.println(" frame: " + frame.isValid());
52
System.out.println(" panel: " + panel.isValid());
53
System.out.println(" button: " + button.isValid());
54
}
55
56
private static void fail(String msg) {
57
frame.dispose();
58
throw new RuntimeException(msg);
59
}
60
61
private static void check(String n, Component c, boolean v) {
62
if (c.isValid() != v) {
63
fail(n + ".isValid() = " + c.isValid() + "; expected: " + v);
64
}
65
}
66
private static void check(String str, boolean f, boolean p, boolean b) {
67
printState(str);
68
69
check("frame", frame, f);
70
check("panel", panel, p);
71
check("button", button, b);
72
}
73
74
public static void main(String[] args) {
75
// setup
76
frame.add(panel);
77
panel.add(button);
78
frame.setBounds(200, 200, 300, 200);
79
frame.setVisible(true);
80
sleep();
81
check("Upon showing", true, true, true);
82
83
button.setBounds(1, 1, 30, 30);
84
sleep();
85
check("button.setBounds():", true, false, false);
86
87
button.revalidate();
88
sleep();
89
check("button.revalidate():", true, true, true);
90
91
button.setBounds(1, 1, 30, 30);
92
sleep();
93
check("button.setBounds():", true, false, false);
94
95
panel.revalidate();
96
sleep();
97
// because the panel's validate root is actually OK
98
check("panel.revalidate():", true, false, false);
99
100
button.revalidate();
101
sleep();
102
check("button.revalidate():", true, true, true);
103
104
panel.setBounds(2, 2, 125, 130);
105
sleep();
106
check("panel.setBounds():", false, false, true);
107
108
button.revalidate();
109
sleep();
110
check("button.revalidate():", false, true, true);
111
112
panel.setBounds(3, 3, 152, 121);
113
sleep();
114
check("panel.setBounds():", false, false, true);
115
116
panel.revalidate();
117
sleep();
118
check("panel.revalidate():", true, true, true);
119
120
// cleanup
121
frame.dispose();
122
}
123
}
124
125