  // Swing JListExample - Derek Molloy

  import javax.swing.*;
  import javax.swing.event.*;
  import java.awt.*; 
  import java.awt.event.*;

  public class JListExample extends JFrame implements ListSelectionListener
  {	
	JList myJList;

	public JListExample()
	{
		super("JList Example");
	
		String[] data = {"Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"};
		
 		myJList = new JList(data);
		myJList.addListSelectionListener(this);

		JScrollPane p = new JScrollPane(this.myJList,
			JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
			JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);

		this.getContentPane().add("Center", p); 	 

		this.pack(); 
		this.show();	 
	}

	public void valueChanged(ListSelectionEvent e)
	{
		JOptionPane.showMessageDialog(this, "You selected : " + myJList.getSelectedValue(), 
			"Selection", JOptionPane.INFORMATION_MESSAGE);
	}
	
	public static void main(String[] args)
	{
		new JListExample();
	}
  }

 