home *** CD-ROM | disk | FTP | other *** search
/ PC Online 1998 January / PCO0198.ISO / 1&1 / java.z / java_301 / java / awt / Checkbox.class (.txt) < prev    next >
Encoding:
Java Class File  |  1996-10-20  |  2.5 KB  |  99 lines

  1. package java.awt;
  2.  
  3. import java.awt.peer.CheckboxPeer;
  4.  
  5. public class Checkbox extends Component {
  6.    String label;
  7.    boolean state;
  8.    CheckboxGroup group;
  9.  
  10.    void setStateInternal(boolean state) {
  11.       this.state = state;
  12.       CheckboxPeer peer = (CheckboxPeer)super.peer;
  13.       if (peer != null) {
  14.          peer.setState(state);
  15.       }
  16.  
  17.    }
  18.  
  19.    public Checkbox() {
  20.    }
  21.  
  22.    public Checkbox(String label) {
  23.       this.label = label;
  24.    }
  25.  
  26.    public Checkbox(String label, CheckboxGroup group, boolean state) {
  27.       this.label = label;
  28.       this.state = state;
  29.       this.group = group;
  30.       if (state && group != null) {
  31.          group.setCurrent(this);
  32.       }
  33.  
  34.    }
  35.  
  36.    public synchronized void addNotify() {
  37.       super.peer = ((Component)this).getToolkit().createCheckbox(this);
  38.       super.addNotify();
  39.    }
  40.  
  41.    public String getLabel() {
  42.       return this.label;
  43.    }
  44.  
  45.    public void setLabel(String label) {
  46.       this.label = label;
  47.       CheckboxPeer peer = (CheckboxPeer)super.peer;
  48.       if (peer != null) {
  49.          peer.setLabel(label);
  50.       }
  51.  
  52.    }
  53.  
  54.    public boolean getState() {
  55.       return this.state;
  56.    }
  57.  
  58.    public void setState(boolean state) {
  59.       CheckboxGroup group = this.group;
  60.       if (group != null) {
  61.          if (state) {
  62.             group.setCurrent(this);
  63.          } else if (group.getCurrent() == this) {
  64.             state = true;
  65.          }
  66.       }
  67.  
  68.       this.setStateInternal(state);
  69.    }
  70.  
  71.    public CheckboxGroup getCheckboxGroup() {
  72.       return this.group;
  73.    }
  74.  
  75.    public void setCheckboxGroup(CheckboxGroup g) {
  76.       CheckboxGroup group = this.group;
  77.       if (group != null) {
  78.          group.setCurrent((Checkbox)null);
  79.       }
  80.  
  81.       this.group = g;
  82.       CheckboxPeer peer = (CheckboxPeer)super.peer;
  83.       if (peer != null) {
  84.          peer.setCheckboxGroup(g);
  85.       }
  86.  
  87.    }
  88.  
  89.    protected String paramString() {
  90.       String str = super.paramString();
  91.       String label = this.label;
  92.       if (label != null) {
  93.          str = str + ",label=" + label;
  94.       }
  95.  
  96.       return str + ",state=" + this.state;
  97.    }
  98. }
  99.