/*
Get All Items From AWT List Example
This java example shows how to get all items from a list using Java AWT
List class.
*/
import java.applet.Applet;
import java.awt.Graphics;
import java.awt.List;
/*
<applet code="GetAllItemsExample" width=200 height=200>
</applet>
*/
public class GetAllItemsExample extends Applet{
List list = null;
public void init(){
//create a list
list = new List(5, true);
//add items to a list
list.add("One");
list.add("Two");
list.add("Three");
list.add("Four");
list.add("Five");
list.add("Six");
list.add("Seven");
//add list
add(list);
}
public void paint(Graphics g){
g.drawString("Items in the list are:" , 10, 120);
/*
* To get all items from a list, use
* String[] getItems()
* method.
*/
String[] items = list.getItems();
int y = 140;
for(int i=0; i < items.length; i++){
g.drawString(items[i],10, y);
y = y+ 20;
}
}
}
Example Output

Bookmark/Search this post with: