24 */ 25 package javax.swing; 26 27 import java.awt.*; 28 import java.awt.event.*; 29 import java.beans.*; 30 31 import javax.swing.plaf.*; 32 import javax.accessibility.*; 33 34 import java.io.ObjectOutputStream; 35 import java.io.ObjectInputStream; 36 import java.io.IOException; 37 38 39 /** 40 * An implementation of a radio button -- an item that can be selected or 41 * deselected, and which displays its state to the user. 42 * Used with a {@link ButtonGroup} object to create a group of buttons 43 * in which only one button at a time can be selected. (Create a ButtonGroup 44 * object and use its <code>add</code> method to include the JRadioButton objects 45 * in the group.) 46 * <blockquote> 47 * <strong>Note:</strong> 48 * The ButtonGroup object is a logical grouping -- not a physical grouping. 49 * To create a button panel, you should still create a {@link JPanel} or similar 50 * container-object and add a {@link javax.swing.border.Border} to it to set it off from surrounding 51 * components. 52 * </blockquote> 53 * <p> 54 * Buttons can be configured, and to some degree controlled, by 55 * <code><a href="Action.html">Action</a></code>s. Using an 56 * <code>Action</code> with a button has many benefits beyond directly 57 * configuring a button. Refer to <a href="Action.html#buttonActions"> 58 * Swing Components Supporting <code>Action</code></a> for more 59 * details, and you can find more information in <a 60 * href="http://docs.oracle.com/javase/tutorial/uiswing/misc/action.html">How 61 * to Use Actions</a>, a section in <em>The Java Tutorial</em>. 62 * <p> 63 * See <a href="http://docs.oracle.com/javase/tutorial/uiswing/components/button.html">How to Use Buttons, Check Boxes, and Radio Buttons</a> 64 * in <em>The Java Tutorial</em> 65 * for further documentation. 66 * <p> 67 * <strong>Warning:</strong> Swing is not thread safe. For more 68 * information see <a 69 * href="package-summary.html#threading">Swing's Threading 70 * Policy</a>. 71 * <p> 72 * <strong>Warning:</strong> 73 * Serialized objects of this class will not be compatible with 74 * future Swing releases. The current serialization support is 75 * appropriate for short term storage or RMI between applications running 76 * the same version of Swing. As of 1.4, support for long term storage 77 * of all JavaBeans™ 78 * has been added to the <code>java.beans</code> package. 79 * Please see {@link java.beans.XMLEncoder}. 80 * 81 * @beaninfo 82 * attribute: isContainer false 83 * description: A component which can display it's state as selected or deselected. 84 * 85 * @see ButtonGroup 86 * @see JCheckBox 87 * @author Jeff Dinkins 88 * @since 1.2 89 */ 90 @SuppressWarnings("serial") // Same-version serialization only 91 public class JRadioButton extends JToggleButton implements Accessible { 92 93 /** 94 * @see #getUIClassID 95 * @see #readObject 96 */ 97 private static final String uiClassID = "RadioButtonUI"; 98 224 * See readObject() and writeObject() in JComponent for more 225 * information about serialization in Swing. 226 */ 227 private void writeObject(ObjectOutputStream s) throws IOException { 228 s.defaultWriteObject(); 229 if (getUIClassID().equals(uiClassID)) { 230 byte count = JComponent.getWriteObjCounter(this); 231 JComponent.setWriteObjCounter(this, --count); 232 if (count == 0 && ui != null) { 233 ui.installUI(this); 234 } 235 } 236 } 237 238 239 /** 240 * Returns a string representation of this JRadioButton. This method 241 * is intended to be used only for debugging purposes, and the 242 * content and format of the returned string may vary between 243 * implementations. The returned string may be empty but may not 244 * be <code>null</code>. 245 * 246 * @return a string representation of this JRadioButton. 247 */ 248 protected String paramString() { 249 return super.paramString(); 250 } 251 252 253 ///////////////// 254 // Accessibility support 255 //////////////// 256 257 258 /** 259 * Gets the AccessibleContext associated with this JRadioButton. 260 * For JRadioButtons, the AccessibleContext takes the form of an 261 * AccessibleJRadioButton. 262 * A new AccessibleJRadioButton instance is created if necessary. 263 * 264 * @return an AccessibleJRadioButton that serves as the 265 * AccessibleContext of this JRadioButton 266 * @beaninfo 267 * expert: true 268 * description: The AccessibleContext associated with this Button 269 */ 270 public AccessibleContext getAccessibleContext() { 271 if (accessibleContext == null) { 272 accessibleContext = new AccessibleJRadioButton(); 273 } 274 return accessibleContext; 275 } 276 277 /** 278 * This class implements accessibility support for the 279 * <code>JRadioButton</code> class. It provides an implementation of the 280 * Java Accessibility API appropriate to radio button 281 * user-interface elements. 282 * <p> 283 * <strong>Warning:</strong> 284 * Serialized objects of this class will not be compatible with 285 * future Swing releases. The current serialization support is 286 * appropriate for short term storage or RMI between applications running 287 * the same version of Swing. As of 1.4, support for long term storage 288 * of all JavaBeans™ 289 * has been added to the <code>java.beans</code> package. 290 * Please see {@link java.beans.XMLEncoder}. 291 */ 292 @SuppressWarnings("serial") // Same-version serialization only 293 protected class AccessibleJRadioButton extends AccessibleJToggleButton { 294 295 /** 296 * Get the role of this object. 297 * 298 * @return an instance of AccessibleRole describing the role of the object 299 * @see AccessibleRole 300 */ 301 public AccessibleRole getAccessibleRole() { 302 return AccessibleRole.RADIO_BUTTON; 303 } 304 305 } // inner class AccessibleJRadioButton 306 } | 24 */ 25 package javax.swing; 26 27 import java.awt.*; 28 import java.awt.event.*; 29 import java.beans.*; 30 31 import javax.swing.plaf.*; 32 import javax.accessibility.*; 33 34 import java.io.ObjectOutputStream; 35 import java.io.ObjectInputStream; 36 import java.io.IOException; 37 38 39 /** 40 * An implementation of a radio button -- an item that can be selected or 41 * deselected, and which displays its state to the user. 42 * Used with a {@link ButtonGroup} object to create a group of buttons 43 * in which only one button at a time can be selected. (Create a ButtonGroup 44 * object and use its {@code add} method to include the JRadioButton objects 45 * in the group.) 46 * <blockquote> 47 * <strong>Note:</strong> 48 * The ButtonGroup object is a logical grouping -- not a physical grouping. 49 * To create a button panel, you should still create a {@link JPanel} or similar 50 * container-object and add a {@link javax.swing.border.Border} to it to set it off from surrounding 51 * components. 52 * </blockquote> 53 * <p> 54 * Buttons can be configured, and to some degree controlled, by 55 * <code><a href="Action.html">Action</a></code>s. Using an 56 * {@code Action} with a button has many benefits beyond directly 57 * configuring a button. Refer to <a href="Action.html#buttonActions"> 58 * Swing Components Supporting {@code Action}</a> for more 59 * details, and you can find more information in <a 60 * href="http://docs.oracle.com/javase/tutorial/uiswing/misc/action.html">How 61 * to Use Actions</a>, a section in <em>The Java Tutorial</em>. 62 * <p> 63 * See <a href="http://docs.oracle.com/javase/tutorial/uiswing/components/button.html">How to Use Buttons, Check Boxes, and Radio Buttons</a> 64 * in <em>The Java Tutorial</em> 65 * for further documentation. 66 * <p> 67 * <strong>Warning:</strong> Swing is not thread safe. For more 68 * information see <a 69 * href="package-summary.html#threading">Swing's Threading 70 * Policy</a>. 71 * <p> 72 * <strong>Warning:</strong> 73 * Serialized objects of this class will not be compatible with 74 * future Swing releases. The current serialization support is 75 * appropriate for short term storage or RMI between applications running 76 * the same version of Swing. As of 1.4, support for long term storage 77 * of all JavaBeans™ 78 * has been added to the {@code java.beans} package. 79 * Please see {@link java.beans.XMLEncoder}. 80 * 81 * @beaninfo 82 * attribute: isContainer false 83 * description: A component which can display it's state as selected or deselected. 84 * 85 * @see ButtonGroup 86 * @see JCheckBox 87 * @author Jeff Dinkins 88 * @since 1.2 89 */ 90 @SuppressWarnings("serial") // Same-version serialization only 91 public class JRadioButton extends JToggleButton implements Accessible { 92 93 /** 94 * @see #getUIClassID 95 * @see #readObject 96 */ 97 private static final String uiClassID = "RadioButtonUI"; 98 224 * See readObject() and writeObject() in JComponent for more 225 * information about serialization in Swing. 226 */ 227 private void writeObject(ObjectOutputStream s) throws IOException { 228 s.defaultWriteObject(); 229 if (getUIClassID().equals(uiClassID)) { 230 byte count = JComponent.getWriteObjCounter(this); 231 JComponent.setWriteObjCounter(this, --count); 232 if (count == 0 && ui != null) { 233 ui.installUI(this); 234 } 235 } 236 } 237 238 239 /** 240 * Returns a string representation of this JRadioButton. This method 241 * is intended to be used only for debugging purposes, and the 242 * content and format of the returned string may vary between 243 * implementations. The returned string may be empty but may not 244 * be {@code null}. 245 * 246 * @return a string representation of this JRadioButton. 247 */ 248 protected String paramString() { 249 return super.paramString(); 250 } 251 252 253 ///////////////// 254 // Accessibility support 255 //////////////// 256 257 258 /** 259 * Gets the AccessibleContext associated with this JRadioButton. 260 * For JRadioButtons, the AccessibleContext takes the form of an 261 * AccessibleJRadioButton. 262 * A new AccessibleJRadioButton instance is created if necessary. 263 * 264 * @return an AccessibleJRadioButton that serves as the 265 * AccessibleContext of this JRadioButton 266 * @beaninfo 267 * expert: true 268 * description: The AccessibleContext associated with this Button 269 */ 270 public AccessibleContext getAccessibleContext() { 271 if (accessibleContext == null) { 272 accessibleContext = new AccessibleJRadioButton(); 273 } 274 return accessibleContext; 275 } 276 277 /** 278 * This class implements accessibility support for the 279 * {@code JRadioButton} class. It provides an implementation of the 280 * Java Accessibility API appropriate to radio button 281 * user-interface elements. 282 * <p> 283 * <strong>Warning:</strong> 284 * Serialized objects of this class will not be compatible with 285 * future Swing releases. The current serialization support is 286 * appropriate for short term storage or RMI between applications running 287 * the same version of Swing. As of 1.4, support for long term storage 288 * of all JavaBeans™ 289 * has been added to the {@code java.beans} package. 290 * Please see {@link java.beans.XMLEncoder}. 291 */ 292 @SuppressWarnings("serial") // Same-version serialization only 293 protected class AccessibleJRadioButton extends AccessibleJToggleButton { 294 295 /** 296 * Get the role of this object. 297 * 298 * @return an instance of AccessibleRole describing the role of the object 299 * @see AccessibleRole 300 */ 301 public AccessibleRole getAccessibleRole() { 302 return AccessibleRole.RADIO_BUTTON; 303 } 304 305 } // inner class AccessibleJRadioButton 306 } |