List
Multiple selections may be enabled by passing true as the second argument to the List constructor.
Corresponding source code:
import java.applet.*;
import java.awt.*;
public class ListWidget extends Applet {
public void init()
{
String[] items={"Seattle", "Washington",
"New York", "Chicago", "Miami",
"San Jose", "Denver" };
Selector s = new Selector(5, items);
add(s);
}
}
class Selector extends List {
public Selector(int numItemsToDisplayAtOnce, String[] elements)
{
// create a list box that doesn't allow multiple selections
super(numItemsToDisplayAtOnce, false);
// add the list of elements to the list box
for (int i=0; i<elements.length; i++) {
addItem(elements[i]);
}
}
}
Method(s) of note:
Related Magercise(s):