Choices and Lists

How do I avoid display flicker when updating the contents of a Choice object?



How do you delete an item from a Choice list?



How do I trap the event where an item is selected from a List or Choice object?


(Submitted by Qing Gong)
The following is the sample code provided by the editor. But this code can only trap double click on a list item. To trap a single click selection, the Event.LIST_SELECT should be captured. I.e., add another "if" statement in the following code:
if (e.id == Event.LIST_SELECT) {...}
(Submitted by the editor)
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);
	}

	...
}