Login    New User    Forgot Password    Help      

Choice Box

Java Tutorials

Example


// choice list
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
/*
<applet code="control5" width=250 height=300>

</applet>
*/
public class control5 extends Applet implements ItemListener
{
String msg="";
Choice fn,bn;
public void init()
{
fn=new Choice();
bn=new Choice();
// Add items to list
fn.add("Java");
fn.add("Visual Basic ");
fn.add(".Net");

bn.add("Oracle");
bn.add("Foxpro");
bn.add("Access");
bn.add("Dbase");

add(bn);
add(fn);

bn.addItemListener(this);
fn.addItemListener(this);
}

public void itemStateChanged(ItemEvent ie)
{
repaint();
}
public void paint(Graphics g)
{
msg="You selected";
msg=msg+fn.getSelectedItem();
msg+=" and ";
msg+=bn.getSelectedItem();
g.drawString(msg,6,100);
}
}

Output

Output in applet

Java Tutorials