home *** CD-ROM | disk | FTP | other *** search
/ PC Plus SuperCD (UK) 2000 March / pcp161a.iso / handson / files / copyjava.exe / com / sun / java / swing / ButtonGroup.class (.txt) < prev    next >
Encoding:
Java Class File  |  1998-02-26  |  1.4 KB  |  56 lines

  1. package com.sun.java.swing;
  2.  
  3. import java.io.Serializable;
  4. import java.util.Enumeration;
  5. import java.util.Vector;
  6.  
  7. public class ButtonGroup implements Serializable {
  8.    protected Vector buttons = new Vector();
  9.    ButtonModel selection;
  10.  
  11.    public void add(AbstractButton var1) {
  12.       if (var1 != null) {
  13.          this.buttons.addElement(var1);
  14.          if (this.selection == null && var1.isSelected()) {
  15.             this.selection = var1.getModel();
  16.          }
  17.  
  18.          var1.getModel().setGroup(this);
  19.       }
  20.    }
  21.  
  22.    public void remove(AbstractButton var1) {
  23.       if (var1 != null) {
  24.          this.buttons.removeElement(var1);
  25.          if (var1.getModel() == this.selection) {
  26.             this.selection = null;
  27.          }
  28.  
  29.          var1.getModel().setGroup((ButtonGroup)null);
  30.       }
  31.    }
  32.  
  33.    public Enumeration getElements() {
  34.       return this.buttons.elements();
  35.    }
  36.  
  37.    public ButtonModel getSelection() {
  38.       return this.selection;
  39.    }
  40.  
  41.    public void setSelected(ButtonModel var1, boolean var2) {
  42.       if (var2 && var1 != this.selection) {
  43.          ButtonModel var3 = this.selection;
  44.          this.selection = var1;
  45.          if (var3 != null) {
  46.             var3.setSelected(false);
  47.          }
  48.       }
  49.  
  50.    }
  51.  
  52.    public boolean isSelected(ButtonModel var1) {
  53.       return var1 == this.selection;
  54.    }
  55. }
  56.