For either a Choice or a List, you can do this:
class MyChoice extends Choice
{
public boolean handleEvent(Event e)
{
if (e.id == Event.ACTION_EVENT)
{
System.out.println(e.arg);
// this will print the string value of the
// item selected - either "item 1" or "item 2"
return true;
}
return super.handleEvent(e);
}
}
public class C extends Applet
{
Frame frame;
Choice choice;
public C(Frame f)
{
frame = f;
setBackground(Color.blue);
choice = new MyChoice(); // instantiate the Choice
choice.addItem("item 1"); // add an item to the Choice
choice.addItem("item 2"); // add a second item
add(choice);
}
...
}