Tuesday, March 10, 2015

Get Selected Item From Single Select AWT List in java



Get Selected Item From Single Select AWT List

import java.applet.Applet;
import java.awt.Graphics;
import java.awt.List;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
public class GetSelectedItemFromSingleSelectExample extends Applet implements ItemListener
{  
List list = null;
public void init()
{
list = new List(5, false);
list.add("One");
list.add("Two");
list.add("Three");
list.add("Four");
list.add("Five");
list.add("Six");
list.add("Seven");
add(list);
list.addItemListener(this);
}
public void paint(Graphics g)
{
g.drawString("Selected Item: "+ list.getSelectedItem(), 10, 120);
}
public void itemStateChanged(ItemEvent arg0)
                    {
repaint();     
  }
}

No comments:

Post a Comment