//if user click on any of the list option background color will be changed according //to the option.
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
public class listdemo extends Applet implements ItemListener
{
List cc;
String s;
public void init()
{
cc = new List();
cc.add("Red");
cc.add("Green");
cc.add("Blue");
add(cc);
cc.addItemListener(this);
}
public void itemStateChanged(ItemEvent e)
{
repaint();
}
public void paint(Graphics g)
{
s=cc.getSelectedItem();
if (s=="Red")
{
setBackground(Color.red);
}
if (s=="Green")
{
setBackground(Color.green);
}
if (s=="Blue")
{
setBackground(Color.blue);
}
}
};
No comments:
Post a Comment