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