Lists:
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
/*<applet code="ListDemo" width=300 height=300></applet>*/
public class ListDemo extends Applet implements ActionListener, ItemListener
{
public void init()
{
List lst=new List();
lst.add("Red");
lst.add("Green");
lst.add("Blue");
lst.add("Yellow");
lst.add("LightGray");
lst.addActionListener(this);
lst.addItemListener(this);
add(lst);
}
public void actionPerformed(ActionEvent ae)
{
String s=ae.getActionCommand();
if(s.equals("Red"))
setBackground(Color.red);
else if(s.equals("Green"))
setBackground(Color.green);
else if(s.equals("Blue"))
setBackground(Color.blue);
else if(s.equals("Yellow"))
setBackground(Color.yellow);
else if(s.equals("LightGray"))
setBackground(Color.lightGray);
}
public void itemStateChanged(ItemEvent ie)
{
List lst=(List)ie.getItemSelectable();
String s=lst.getSelectedItem();
if(s.equals("Red"))
setBackground(Color.red);
else if(s.equals("Green"))
setBackground(Color.green);
else if(s.equals("Blue"))
setBackground(Color.blue);
else if(s.equals("Yellow"))
setBackground(Color.yellow);
else if(s.equals("LightGray"))
setBackground(Color.lightGray);
}
}
Comments
Post a Comment