Login    New User    Forgot Password    Help      

Java List

Java Tutorials

Example

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

</applet>
*/
public class control6 extends Applet implements ItemListener
{
String msg="";
List fn,bn;
public void init()
{
fn=new List(3,true);
bn=new List(4,false);

// 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 ae)
{
repaint();
}

public void paint(Graphics g)
{
int idx[];
int i;
msg="You selected";
idx=fn.getSelectedIndexes();
for(i=0;i<idx.length;i++)
msg+=fn.getItem(idx[i])+ " and ";
msg+=bn.getSelectedItem();
g.drawString(msg,32,200);
}
}

Output

Output in Applet

Java Tutorials