home *** CD-ROM | disk | FTP | other *** search
- package java.awt;
-
- import java.awt.peer.CheckboxPeer;
-
- public class Checkbox extends Component {
- String label;
- boolean state;
- CheckboxGroup group;
-
- void setStateInternal(boolean state) {
- this.state = state;
- CheckboxPeer peer = (CheckboxPeer)super.peer;
- if (peer != null) {
- peer.setState(state);
- }
-
- }
-
- public Checkbox() {
- }
-
- public Checkbox(String label) {
- this.label = label;
- }
-
- public Checkbox(String label, CheckboxGroup group, boolean state) {
- this.label = label;
- this.state = state;
- this.group = group;
- if (state && group != null) {
- group.setCurrent(this);
- }
-
- }
-
- public synchronized void addNotify() {
- super.peer = ((Component)this).getToolkit().createCheckbox(this);
- super.addNotify();
- }
-
- public String getLabel() {
- return this.label;
- }
-
- public void setLabel(String label) {
- this.label = label;
- CheckboxPeer peer = (CheckboxPeer)super.peer;
- if (peer != null) {
- peer.setLabel(label);
- }
-
- }
-
- public boolean getState() {
- return this.state;
- }
-
- public void setState(boolean state) {
- CheckboxGroup group = this.group;
- if (group != null) {
- if (state) {
- group.setCurrent(this);
- } else if (group.getCurrent() == this) {
- state = true;
- }
- }
-
- this.setStateInternal(state);
- }
-
- public CheckboxGroup getCheckboxGroup() {
- return this.group;
- }
-
- public void setCheckboxGroup(CheckboxGroup g) {
- CheckboxGroup group = this.group;
- if (group != null) {
- group.setCurrent((Checkbox)null);
- }
-
- this.group = g;
- CheckboxPeer peer = (CheckboxPeer)super.peer;
- if (peer != null) {
- peer.setCheckboxGroup(g);
- }
-
- }
-
- protected String paramString() {
- String str = super.paramString();
- String label = this.label;
- if (label != null) {
- str = str + ",label=" + label;
- }
-
- return str + ",state=" + this.state;
- }
- }
-