//: Choice1.java
// Using drop-down lists
import java.awt.*;
import java.applet.*;
public class Choice1 extends Applet {
String[] description = { "Ebullient", "Obtuse",
"Recalcitrant", "Brilliant", "Somnescent",
"Timorous", "Florid", "Putrescent" };
TextField t = new TextField(30);
Choice c = new Choice();
Button b = new Button("Add items");
int count = 0;
public void init() {
t.setEditable(false);
for(int i = 0; i < 4; i++)
c.addItem(description[count++]);
add(t);
add(c);
add(b);
}
public boolean action (Event evt, Object arg) {
if(evt.target.equals(c))
t.setText("index: " + c.getSelectedIndex()
+ " " + (String)arg);
else if(evt.target.equals(b)) {
if(count < description.length)
c.addItem(description[count++]);
}
else
return super.action(evt, arg);
return true;
}
} ///:~