Sat Feb 09, 2013 4:34 pm
import java.awt.*;
import java.awt.event.ItemListener;
import java.awt.event.ItemEvent;
import java.applet.Applet;
public class ChoiceExample extends Applet
implements ItemListener {
Choice choiceList; //popup list of choices
Label labelObj;
public void init() {
choiceList = new Choice();
choiceList.addItem("A1");
choiceList.addItem("B1");
choiceList.addItem("C1");
choiceList.addItem("D1");
choiceList.addItemListener(this);
labelObj = new Label();
setLabelText(choiceList.getSelectedIndex(),
choiceList.getSelectedItem());
//Add components to the Applet.
add(choiceList);
add(labelObj);
}
void setLabelText(int num, String text) {
labelObj.setText("Item #" + num + " selected. "
+ "Text = \"" + text + "\".");
}
public void itemStateChanged(ItemEvent e) {
setLabelText(choiceList.getSelectedIndex(),
choiceList.getSelectedItem());
}
}
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com
Powered by phpBB © phpBB Group.