src/share/classes/java/awt/CheckboxGroup.java

Print this page
rev 10048 : 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
Reviewed-by:


  35  * <p>
  36  * The following code example produces a new check box group,
  37  * with three check boxes:
  38  *
  39  * <hr><blockquote><pre>
  40  * setLayout(new GridLayout(3, 1));
  41  * CheckboxGroup cbg = new CheckboxGroup();
  42  * add(new Checkbox("one", cbg, true));
  43  * add(new Checkbox("two", cbg, false));
  44  * add(new Checkbox("three", cbg, false));
  45  * </pre></blockquote><hr>
  46  * <p>
  47  * This image depicts the check box group created by this example:
  48  * <p>
  49  * <img src="doc-files/CheckboxGroup-1.gif"
  50  * alt="Shows three checkboxes, arranged vertically, labeled one, two, and three. Checkbox one is in the on state."
  51  * style="float:center; margin: 7px 10px;">
  52  *
  53  * @author      Sami Shaio
  54  * @see         java.awt.Checkbox
  55  * @since       JDK1.0
  56  */
  57 public class CheckboxGroup implements java.io.Serializable {
  58     /**
  59      * The current choice.
  60      * @serial
  61      * @see #getCurrent()
  62      * @see #setCurrent(Checkbox)
  63      */
  64     Checkbox selectedCheckbox = null;
  65 
  66     /*
  67      * JDK 1.1 serialVersionUID
  68      */
  69     private static final long serialVersionUID = 3729780091441768983L;
  70 
  71     /**
  72      * Creates a new instance of <code>CheckboxGroup</code>.
  73      */
  74     public CheckboxGroup() {
  75     }
  76 
  77     /**
  78      * Gets the current choice from this check box group.
  79      * The current choice is the check box in this
  80      * group that is currently in the "on" state,
  81      * or <code>null</code> if all check boxes in the
  82      * group are off.
  83      * @return   the check box that is currently in the
  84      *                 "on" state, or <code>null</code>.
  85      * @see      java.awt.Checkbox
  86      * @see      java.awt.CheckboxGroup#setSelectedCheckbox
  87      * @since    JDK1.1
  88      */
  89     public Checkbox getSelectedCheckbox() {
  90         return getCurrent();
  91     }
  92 
  93     /**
  94      * @deprecated As of JDK version 1.1,
  95      * replaced by <code>getSelectedCheckbox()</code>.
  96      */
  97     @Deprecated
  98     public Checkbox getCurrent() {
  99         return selectedCheckbox;
 100     }
 101 
 102     /**
 103      * Sets the currently selected check box in this group
 104      * to be the specified check box.
 105      * This method sets the state of that check box to "on" and
 106      * sets all other check boxes in the group to be off.
 107      * <p>
 108      * If the check box argument is <tt>null</tt>, all check boxes
 109      * in this check box group are deselected. If the check box argument
 110      * belongs to a different check box group, this method does
 111      * nothing.
 112      * @param     box   the <code>Checkbox</code> to set as the
 113      *                      current selection.
 114      * @see      java.awt.Checkbox
 115      * @see      java.awt.CheckboxGroup#getSelectedCheckbox
 116      * @since    JDK1.1
 117      */
 118     public void setSelectedCheckbox(Checkbox box) {
 119         setCurrent(box);
 120     }
 121 
 122     /**
 123      * @deprecated As of JDK version 1.1,
 124      * replaced by <code>setSelectedCheckbox(Checkbox)</code>.
 125      */
 126     @Deprecated
 127     public synchronized void setCurrent(Checkbox box) {
 128         if (box != null && box.group != this) {
 129             return;
 130         }
 131         Checkbox oldChoice = this.selectedCheckbox;
 132         this.selectedCheckbox = box;
 133         if (oldChoice != null && oldChoice != box && oldChoice.group == this) {
 134             oldChoice.setState(false);
 135         }
 136         if (box != null && oldChoice != box && !box.getState()) {


  35  * <p>
  36  * The following code example produces a new check box group,
  37  * with three check boxes:
  38  *
  39  * <hr><blockquote><pre>
  40  * setLayout(new GridLayout(3, 1));
  41  * CheckboxGroup cbg = new CheckboxGroup();
  42  * add(new Checkbox("one", cbg, true));
  43  * add(new Checkbox("two", cbg, false));
  44  * add(new Checkbox("three", cbg, false));
  45  * </pre></blockquote><hr>
  46  * <p>
  47  * This image depicts the check box group created by this example:
  48  * <p>
  49  * <img src="doc-files/CheckboxGroup-1.gif"
  50  * alt="Shows three checkboxes, arranged vertically, labeled one, two, and three. Checkbox one is in the on state."
  51  * style="float:center; margin: 7px 10px;">
  52  *
  53  * @author      Sami Shaio
  54  * @see         java.awt.Checkbox
  55  * @since       1.0
  56  */
  57 public class CheckboxGroup implements java.io.Serializable {
  58     /**
  59      * The current choice.
  60      * @serial
  61      * @see #getCurrent()
  62      * @see #setCurrent(Checkbox)
  63      */
  64     Checkbox selectedCheckbox = null;
  65 
  66     /*
  67      * JDK 1.1 serialVersionUID
  68      */
  69     private static final long serialVersionUID = 3729780091441768983L;
  70 
  71     /**
  72      * Creates a new instance of <code>CheckboxGroup</code>.
  73      */
  74     public CheckboxGroup() {
  75     }
  76 
  77     /**
  78      * Gets the current choice from this check box group.
  79      * The current choice is the check box in this
  80      * group that is currently in the "on" state,
  81      * or <code>null</code> if all check boxes in the
  82      * group are off.
  83      * @return   the check box that is currently in the
  84      *                 "on" state, or <code>null</code>.
  85      * @see      java.awt.Checkbox
  86      * @see      java.awt.CheckboxGroup#setSelectedCheckbox
  87      * @since    1.1
  88      */
  89     public Checkbox getSelectedCheckbox() {
  90         return getCurrent();
  91     }
  92 
  93     /**
  94      * @deprecated As of JDK version 1.1,
  95      * replaced by <code>getSelectedCheckbox()</code>.
  96      */
  97     @Deprecated
  98     public Checkbox getCurrent() {
  99         return selectedCheckbox;
 100     }
 101 
 102     /**
 103      * Sets the currently selected check box in this group
 104      * to be the specified check box.
 105      * This method sets the state of that check box to "on" and
 106      * sets all other check boxes in the group to be off.
 107      * <p>
 108      * If the check box argument is <tt>null</tt>, all check boxes
 109      * in this check box group are deselected. If the check box argument
 110      * belongs to a different check box group, this method does
 111      * nothing.
 112      * @param     box   the <code>Checkbox</code> to set as the
 113      *                      current selection.
 114      * @see      java.awt.Checkbox
 115      * @see      java.awt.CheckboxGroup#getSelectedCheckbox
 116      * @since    1.1
 117      */
 118     public void setSelectedCheckbox(Checkbox box) {
 119         setCurrent(box);
 120     }
 121 
 122     /**
 123      * @deprecated As of JDK version 1.1,
 124      * replaced by <code>setSelectedCheckbox(Checkbox)</code>.
 125      */
 126     @Deprecated
 127     public synchronized void setCurrent(Checkbox box) {
 128         if (box != null && box.group != this) {
 129             return;
 130         }
 131         Checkbox oldChoice = this.selectedCheckbox;
 132         this.selectedCheckbox = box;
 133         if (oldChoice != null && oldChoice != box && oldChoice.group == this) {
 134             oldChoice.setState(false);
 135         }
 136         if (box != null && oldChoice != box && !box.getState()) {