Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/javax/swing/Headless/HeadlessJComponent.java
41149 views
1
/*
2
* Copyright (c) 2007, 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
import javax.swing.*;
25
import java.awt.*;
26
import java.util.Locale;
27
28
/*
29
* @test
30
* @summary Check that JComponent constructor and methods do not throw unexpected
31
* exceptions in headless mode
32
* @run main/othervm -Djava.awt.headless=true HeadlessJComponent
33
*/
34
35
public class HeadlessJComponent {
36
public static void main(String args[]) {
37
JComponent ch = new JComponent(){};
38
ch.getAccessibleContext();
39
ch.isFocusTraversable();
40
ch.setEnabled(false);
41
ch.setEnabled(true);
42
ch.requestFocus();
43
ch.requestFocusInWindow();
44
ch.getPreferredSize();
45
ch.getMaximumSize();
46
ch.getMinimumSize();
47
ch.contains(1, 2);
48
Component c1 = ch.add(new Component(){});
49
Component c2 = ch.add(new Component(){});
50
Component c3 = ch.add(new Component(){});
51
Insets ins = ch.getInsets();
52
ch.getAlignmentY();
53
ch.getAlignmentX();
54
ch.getGraphics();
55
ch.setVisible(false);
56
ch.setVisible(true);
57
ch.setForeground(Color.red);
58
ch.setBackground(Color.red);
59
for (String font : Toolkit.getDefaultToolkit().getFontList()) {
60
for (int j = 8; j < 17; j++) {
61
Font f1 = new Font(font, Font.PLAIN, j);
62
Font f2 = new Font(font, Font.BOLD, j);
63
Font f3 = new Font(font, Font.ITALIC, j);
64
Font f4 = new Font(font, Font.BOLD | Font.ITALIC, j);
65
66
ch.setFont(f1);
67
ch.setFont(f2);
68
ch.setFont(f3);
69
ch.setFont(f4);
70
71
ch.getFontMetrics(f1);
72
ch.getFontMetrics(f2);
73
ch.getFontMetrics(f3);
74
ch.getFontMetrics(f4);
75
}
76
}
77
ch.enable();
78
ch.disable();
79
ch.reshape(10, 10, 10, 10);
80
ch.getBounds(new Rectangle(1, 1, 1, 1));
81
ch.getSize(new Dimension(1, 2));
82
ch.getLocation(new Point(1, 2));
83
ch.getX();
84
ch.getY();
85
ch.getWidth();
86
ch.getHeight();
87
ch.isOpaque();
88
ch.isValidateRoot();
89
ch.isOptimizedDrawingEnabled();
90
ch.isDoubleBuffered();
91
ch.getComponentCount();
92
ch.countComponents();
93
ch.getComponent(1);
94
ch.getComponent(2);
95
Component[] cs = ch.getComponents();
96
ch.getLayout();
97
ch.setLayout(new FlowLayout());
98
ch.doLayout();
99
ch.layout();
100
ch.invalidate();
101
ch.validate();
102
ch.remove(0);
103
ch.remove(c2);
104
ch.removeAll();
105
ch.preferredSize();
106
ch.minimumSize();
107
ch.getComponentAt(1, 2);
108
ch.locate(1, 2);
109
ch.getComponentAt(new Point(1, 2));
110
ch.isFocusCycleRoot(new Container());
111
ch.transferFocusBackward();
112
ch.setName("goober");
113
ch.getName();
114
ch.getParent();
115
ch.getGraphicsConfiguration();
116
ch.getTreeLock();
117
ch.getToolkit();
118
ch.isValid();
119
ch.isDisplayable();
120
ch.isVisible();
121
ch.isShowing();
122
ch.isEnabled();
123
ch.enable(false);
124
ch.enable(true);
125
ch.enableInputMethods(false);
126
ch.enableInputMethods(true);
127
ch.show();
128
ch.show(false);
129
ch.show(true);
130
ch.hide();
131
ch.getForeground();
132
ch.isForegroundSet();
133
ch.getBackground();
134
ch.isBackgroundSet();
135
ch.getFont();
136
ch.isFontSet();
137
Container c = new Container();
138
c.add(ch);
139
ch.getLocale();
140
for (Locale locale : Locale.getAvailableLocales())
141
ch.setLocale(locale);
142
143
ch.getColorModel();
144
ch.getLocation();
145
146
boolean exceptions = false;
147
try {
148
ch.getLocationOnScreen();
149
} catch (IllegalComponentStateException e) {
150
exceptions = true;
151
}
152
if (!exceptions)
153
throw new RuntimeException("IllegalComponentStateException did not occur when expected");
154
155
ch.location();
156
ch.setLocation(1, 2);
157
ch.move(1, 2);
158
ch.setLocation(new Point(1, 2));
159
ch.getSize();
160
ch.size();
161
ch.setSize(1, 32);
162
ch.resize(1, 32);
163
ch.setSize(new Dimension(1, 32));
164
ch.resize(new Dimension(1, 32));
165
ch.getBounds();
166
ch.bounds();
167
ch.setBounds(10, 10, 10, 10);
168
ch.setBounds(new Rectangle(10, 10, 10, 10));
169
ch.isLightweight();
170
ch.setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR));
171
ch.getCursor();
172
ch.isCursorSet();
173
ch.inside(1, 2);
174
ch.contains(new Point(1, 2));
175
ch.isFocusable();
176
ch.setFocusable(true);
177
ch.setFocusable(false);
178
ch.transferFocus();
179
ch.getFocusCycleRootAncestor();
180
ch.nextFocus();
181
ch.transferFocusUpCycle();
182
ch.hasFocus();
183
ch.isFocusOwner();
184
ch.toString();
185
ch.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
186
ch.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
187
ch.setComponentOrientation(ComponentOrientation.UNKNOWN);
188
ch.getComponentOrientation();
189
}
190
}
191
192