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
Post a Comment