Thursday, August 22, 2013

PROGRAM FOR JLIST

PROGRAM:
````````````````
import java.awt.*;
import javax.swing.*;
import javax.swing.event.*;

import java.awt.event.*;


public class jlist extends JApplet implements ListSelectionListener
{
JList jlist;
String cities[]={"New York","Bangalore", "Mumbai","Chennai", "Delhi","Tokyo"};
JLabel jl=new JLabel("Select an item");
public void init()
{
setLayout(new GridBagLayout());
jlist=new JList(cities);
jlist.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
JScrollPane jscp=new JScrollPane(jlist);
add(jscp);
add(jl);
}

@Override
public void valueChanged(ListSelectionEvent le)
{
int index=jlist.getSelectedIndex();
if(index!=-1)
{
// jl.setText("Current selection is "+index+".");
showStatus("Current selection is "+cities[index]+".");
}
else
jl.setText("Choose a city.");

}
}

OUTPUT:
~~~~~~~


No comments:

Post a Comment

Animated Social Gadget - Blogger And Wordpress Tips