Design GUI to handle Choice Control event.

 /* Write an applete code to demonstrate usgae of choice control */


import java.awt.*;
import java.awt.event.*;
import java.applet.*;

/*
<applet code="ChoiceDemo" width=300 height=100>
</applet>
*/      

public class ChoiceDemo extends Applet implements ItemListener
{
    Choice c1,c2;
    public void init()
    {
    c1 = new Choice();
    c2 = new Choice();
   
    // add items to first choce controls

    c1.add("Windows XP");
    c1.add("Windows 8");
    c1.add("Windows 10");
    c1.add("Ubuntu");

    // add items to second choce controls

    c2.add("Google Chrome");
    c2.add("Mozila Firefox");
    c2.add("Opera");

    // adding choice controls to applet window
    add(c1);
    add(c2);

    //regisre with event listeners
    c1.addItemListener(this);
    c2.addItemListener(this);
    }
 
    public void itemStateChanged(ItemEvent ie)
    {
    repaint();
    }

    public void paint(Graphics g)
    {
    String msg;
    msg = "Cureent OS = " + c1.getSelectedItem();
    g.drawString(msg,10,100);
   
    msg = "Cureent Browser = " + c2.getSelectedItem();
    g.drawString(msg,10,130);
    }
}

Comments

Popular posts from this blog

Write a Java program that reads an integer number (between 1 and 255) from the user and prints the binary representation of the number. The answer should be printed as a String. Note: The output displayed should contain 8 digits and should be padded with leading 0s(zeros), in case the returned String contains less than 8 characters. For example, if the user enters the value 16, then the output should be 00010000 and if the user enters the value 100, the output should be 01100100 (Hint : You may use String.format() method for the expected output)