Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/awt/Dialog/ChildProperties/ChildDialogProperties.java
41153 views
1
/*
2
* Copyright (c) 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
/*
25
* @test
26
* @key headful
27
* @bug 8057574
28
* @summary Verify that child Dialog does not inherit parent's Properties
29
* @run main ChildDialogProperties
30
*/
31
32
import java.awt.Color;
33
import java.awt.Dialog;
34
import java.awt.Font;
35
import java.awt.Frame;
36
import java.awt.Label;
37
38
public class ChildDialogProperties {
39
40
private Dialog parentDialog;
41
private Dialog dialogChild;
42
private Frame parentFrame;
43
private Dialog frameChildDialog;
44
private Label parentLabel;
45
private Font parentFont;
46
private Label childLabel;
47
48
private static final int WIDTH = 200;
49
private static final int HEIGHT = 200;
50
51
public void testChildPropertiesWithDialogAsParent() {
52
53
parentDialog = new Dialog((Dialog) null, "parent Dialog");
54
parentDialog.setSize(WIDTH, HEIGHT);
55
parentDialog.setLocation(100, 100);
56
parentDialog.setBackground(Color.RED);
57
58
parentLabel = new Label("ParentForegroundAndFont");
59
parentFont = new Font("Courier New", Font.ITALIC, 15);
60
parentDialog.setForeground(Color.BLUE);
61
parentDialog.setFont(parentFont);
62
63
parentDialog.add(parentLabel);
64
parentDialog.setVisible(true);
65
66
dialogChild = new Dialog(parentDialog, "Dialog's child");
67
dialogChild.setSize(WIDTH, HEIGHT);
68
dialogChild.setLocation(WIDTH + 200, 100);
69
childLabel = new Label("ChildForegroundAndFont");
70
dialogChild.add(childLabel);
71
72
dialogChild.setVisible(true);
73
74
if (parentDialog.getBackground() == dialogChild.getBackground()) {
75
dispose();
76
throw new RuntimeException("Child Dialog Should NOT Inherit "
77
+ "Parent Dialog's Background Color");
78
}
79
80
if (parentDialog.getForeground() == dialogChild.getForeground()) {
81
dispose();
82
throw new RuntimeException("Child Dialog Should NOT Inherit "
83
+ "Parent Dialog's Foreground Color");
84
}
85
86
if (parentDialog.getFont() == dialogChild.getFont()) {
87
dispose();
88
throw new RuntimeException("Child Dialog Should NOT Inherit "
89
+ "Parent Dialog's Font Style/Color");
90
}
91
92
}
93
94
public void testChildPropertiesWithFrameAsParent() {
95
96
parentFrame = new Frame("parent Frame");
97
parentFrame.setSize(WIDTH, HEIGHT);
98
parentFrame.setLocation(100, 400);
99
parentFrame.setBackground(Color.BLUE);
100
parentLabel = new Label("ParentForegroundAndFont");
101
parentFont = new Font("Courier New", Font.ITALIC, 15);
102
parentFrame.setForeground(Color.RED);
103
parentFrame.setFont(parentFont);
104
parentFrame.add(parentLabel);
105
parentFrame.setVisible(true);
106
107
frameChildDialog = new Dialog(parentFrame, "Frame's child");
108
frameChildDialog.setSize(WIDTH, HEIGHT);
109
frameChildDialog.setLocation(WIDTH + 200, 400);
110
childLabel = new Label("ChildForegroundAndFont");
111
frameChildDialog.add(childLabel);
112
frameChildDialog.setVisible(true);
113
114
if (parentFrame.getBackground() == frameChildDialog.getBackground()) {
115
dispose();
116
throw new RuntimeException("Child Dialog Should NOT Inherit "
117
+ "Parent Frame's Background Color");
118
}
119
120
if (parentFrame.getForeground() == frameChildDialog.getForeground()) {
121
dispose();
122
throw new RuntimeException("Child Dialog Should NOT Inherit "
123
+ "Parent Frame's Foreground Color");
124
}
125
126
if (parentFrame.getFont() == frameChildDialog.getFont()) {
127
dispose();
128
throw new RuntimeException("Child Dialog Should NOT Inherit "
129
+ "Parent Frame's Font Style/Color");
130
}
131
}
132
133
private void dispose() {
134
135
if (parentDialog != null) {
136
parentDialog.dispose();
137
}
138
if (parentFrame != null) {
139
parentFrame.dispose();
140
}
141
}
142
143
public static void main(String[] args) throws Exception {
144
145
ChildDialogProperties obj = new ChildDialogProperties();
146
// TestCase1: When Parent is Dialog, Child is Dialog
147
obj.testChildPropertiesWithDialogAsParent();
148
// TestCase2: When Parent is Frame, chis is Dialog
149
obj.testChildPropertiesWithFrameAsParent();
150
obj.dispose();
151
}
152
153
}
154
155