home *** CD-ROM | disk | FTP | other *** search
/ Dynamic HTML Construction Kit / Dynamic HTML Construction Kit.iso / earthlink / nscomm / java40.jar / java / awt / Choice.class (.txt) < prev    next >
Encoding:
Java Class File  |  1997-11-03  |  1.8 KB  |  79 lines

  1. package java.awt;
  2.  
  3. import java.awt.peer.ChoicePeer;
  4. import java.util.Vector;
  5.  
  6. public class Choice extends Component {
  7.    Vector pItems = new Vector();
  8.    int selectedIndex = -1;
  9.  
  10.    public synchronized void addNotify() {
  11.       if (super.peer == null) {
  12.          super.peer = ((Component)this).getToolkit().createChoice(this);
  13.       }
  14.  
  15.       super.addNotify();
  16.    }
  17.  
  18.    public int countItems() {
  19.       return this.pItems.size();
  20.    }
  21.  
  22.    public String getItem(int var1) {
  23.       return (String)this.pItems.elementAt(var1);
  24.    }
  25.  
  26.    public synchronized void addItem(String var1) {
  27.       if (var1 == null) {
  28.          throw new NullPointerException();
  29.       } else {
  30.          this.pItems.addElement(var1);
  31.          ChoicePeer var2 = (ChoicePeer)super.peer;
  32.          if (var2 != null) {
  33.             var2.addItem(var1, this.pItems.size() - 1);
  34.          }
  35.  
  36.          if (this.selectedIndex < 0) {
  37.             this.select(0);
  38.          }
  39.  
  40.       }
  41.    }
  42.  
  43.    public String getSelectedItem() {
  44.       int var1 = this.selectedIndex;
  45.       return var1 >= 0 ? this.getItem(var1) : null;
  46.    }
  47.  
  48.    public int getSelectedIndex() {
  49.       return this.selectedIndex;
  50.    }
  51.  
  52.    public synchronized void select(int var1) {
  53.       if (var1 >= this.pItems.size()) {
  54.          throw new IllegalArgumentException("illegal Choice item position: " + var1);
  55.       } else {
  56.          if (this.pItems.size() > 0) {
  57.             this.selectedIndex = var1;
  58.             ChoicePeer var2 = (ChoicePeer)super.peer;
  59.             if (var2 != null) {
  60.                var2.select(var1);
  61.             }
  62.          }
  63.  
  64.       }
  65.    }
  66.  
  67.    public void select(String var1) {
  68.       int var2 = this.pItems.indexOf(var1);
  69.       if (var2 >= 0) {
  70.          this.select(var2);
  71.       }
  72.  
  73.    }
  74.  
  75.    protected String paramString() {
  76.       return super.paramString() + ",current=" + this.getSelectedItem();
  77.    }
  78. }
  79.