Example of choice class (awt)
import
java.applet.*;
import
java.awt.*;
import
java.awt.event.*;
/*
<applet
code="ChoiceDemo" height=200 width=200>
</applet>
*/
public class
ChoiceDemo extends Applet implements ItemListener
{
TextField tf;
public void init()
{
Choice ch=new Choice();
/* add the items to the choice control*/
ch.add("Computer
Science");
ch.add("Information
Technology");
ch.add("Mechanical");
ch.add("Electronics");
ch.add("Instrumentation");
add(ch);
ch.addItemListener(this);
tf=new TextField(25);
add(tf);
}
public void
itemStateChanged(ItemEvent ie)
{
Choice
c=(Choice)ie.getItemSelectable();
tf.setText(c.getSelectedItem());
}
}
Comments
Post a Comment