JAVA Program to Implement Choice List

JAVA Program to Implement Choice List:

/*
<applet code="choice.class" width=250 height=200>
</applet>
*/
import java.awt.*;
import java.awt.event.*;
import java.applet.*;

public class choice extends Applet implements ItemListener
{
    String msg = "";
    Choice os,browser;

    public void init()
    {
        os = new Choice();
        browser = new Choice();
        // add item to os list
        os.add("Windows 98/XP");
        os.add("Windows NT/2000");
        os.add("Solaris");
        os.add("MacOS");

        // add item to brower
        browser.add("Netscape 3.x");
        browser.add("Netscape 4.x");
        browser.add("Netscape 5.x");
        browser.add("Netscape 6.x");

        browser.add("Internet Explorer 4.0");
        browser.add("Internet Explorer 5.0");
        browser.add("Internet Explorer 6.0");

        browser.add("Lynx 2.4");

        browser.select("Netscape 4.x");

        //add choice lists to window

        add(os);
        add(browser);

        os.addItemListener(this);
        browser.addItemListener(this);
    }

    public void itemStateChanged(ItemEvent ie)
    {
        repaint();
    }

    // Display current selections.

    public void paint(Graphics g)
    {
        msg = "Current operating : ";
        msg += os.getSelectedItem();
        g.drawString(msg, 6, 120);

        msg = "current Browser : ";
        msg += browser.getSelectedItem();
        g.drawString(msg, 6, 140);
    }
}

OUTPUT:

JAVA Program to Implement Choice List

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.