home *** CD-ROM | disk | FTP | other *** search
/ MACD 4 / MACD4.iso / Internet / Java / ui / components / example / ChoiceDemo.class (.txt) < prev    next >
Encoding:
Java Class File  |  1978-03-06  |  1.4 KB  |  37 lines

  1. import java.applet.Applet;
  2. import java.awt.Choice;
  3. import java.awt.Container;
  4. import java.awt.Event;
  5. import java.awt.Label;
  6.  
  7. public class ChoiceDemo extends Applet {
  8.    Choice choice;
  9.    Label label;
  10.  
  11.    public void init() {
  12.       this.choice = new Choice();
  13.       this.choice.addItem("ichi");
  14.       this.choice.addItem("ni");
  15.       this.choice.addItem("san");
  16.       this.choice.addItem("yon");
  17.       this.label = new Label();
  18.       this.setLabelText(this.choice.getSelectedIndex(), this.choice.getSelectedItem());
  19.       ((Container)this).add(this.choice);
  20.       ((Container)this).add(this.label);
  21.       ((Container)this).validate();
  22.    }
  23.  
  24.    void setLabelText(int var1, String var2) {
  25.       this.label.setText("Item #" + var1 + " selected. " + "Text = \"" + var2 + "\".");
  26.    }
  27.  
  28.    public boolean action(Event var1, Object var2) {
  29.       if (var1.target instanceof Choice) {
  30.          this.setLabelText(this.choice.getSelectedIndex(), (String)var2);
  31.          return true;
  32.       } else {
  33.          return false;
  34.       }
  35.    }
  36. }
  37.