home *** CD-ROM | disk | FTP | other *** search
/ PC Online 1997 November / PCO1197.ISO / FilesBBS / WIN95 / NET_COM / N32E403.EXE / nav40l.z / java40.jar / java / awt / Choice.class (.txt) < prev    next >
Encoding:
Java Class File  |  1997-09-04  |  1.8 KB  |  76 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.       super.peer = ((Component)this).getToolkit().createChoice(this);
  12.       super.addNotify();
  13.    }
  14.  
  15.    public int countItems() {
  16.       return this.pItems.size();
  17.    }
  18.  
  19.    public String getItem(int var1) {
  20.       return (String)this.pItems.elementAt(var1);
  21.    }
  22.  
  23.    public synchronized void addItem(String var1) {
  24.       if (var1 == null) {
  25.          throw new NullPointerException();
  26.       } else {
  27.          this.pItems.addElement(var1);
  28.          ChoicePeer var2 = (ChoicePeer)super.peer;
  29.          if (var2 != null) {
  30.             var2.addItem(var1, this.pItems.size() - 1);
  31.          }
  32.  
  33.          if (this.selectedIndex < 0) {
  34.             this.select(0);
  35.          }
  36.  
  37.       }
  38.    }
  39.  
  40.    public String getSelectedItem() {
  41.       int var1 = this.selectedIndex;
  42.       return var1 >= 0 ? this.getItem(var1) : null;
  43.    }
  44.  
  45.    public int getSelectedIndex() {
  46.       return this.selectedIndex;
  47.    }
  48.  
  49.    public synchronized void select(int var1) {
  50.       if (var1 >= this.pItems.size()) {
  51.          throw new IllegalArgumentException("illegal Choice item position: " + var1);
  52.       } else {
  53.          if (this.pItems.size() > 0) {
  54.             this.selectedIndex = var1;
  55.             ChoicePeer var2 = (ChoicePeer)super.peer;
  56.             if (var2 != null) {
  57.                var2.select(var1);
  58.             }
  59.          }
  60.  
  61.       }
  62.    }
  63.  
  64.    public void select(String var1) {
  65.       int var2 = this.pItems.indexOf(var1);
  66.       if (var2 >= 0) {
  67.          this.select(var2);
  68.       }
  69.  
  70.    }
  71.  
  72.    protected String paramString() {
  73.       return super.paramString() + ",current=" + this.getSelectedItem();
  74.    }
  75. }
  76.