What is wrong with my code.
I have created a JList, added items and pushed it to the left(BorderLayout.WEST). Every time a list item is clicked, i want a panel to be displayed to the right of the list. But the problem is when a list item is selected and the listener is run, reaches to the if selection where according to the index selected a panel related to it from another class (with inner classes) should be displayed(but it does not!) . . .
        import java.awt.BorderLayout;
        import java.awt.CardLayout;
        import java.awt.Color;
        import java.awt.Font;
        import javax.swing.JFrame;
        import javax.swing.JList;
        import javax.swing.JPanel;
        import javax.swing.ListSelectionModel;
        import javax.swing.event.ListSelectionEvent;
        import javax.swing.event.ListSelectionListener;
    public class MainGUI extends JFrame{
    ListListeners listListeners = new ListListeners();
    JList list = new JList(
            new String[]{"Create Account","Borrow Book","Return Book","Add Book","Delete Book","Display Details"}
            );
    JPanel panel1 = new JPanel();
    public MainGUI()
    {
        CardLayout cardLayout = new CardLayout();
        JPanel panel = new JPanel();
        list.setForeground(Color.RED);
        list.setBackground(Color.WHITE);
        list.setSelectionForeground(Color.GREEN);
        list.setSelectionBackground(Color.LIGHT_GRAY);
        list.setFixedCellWidth(150);
        list.setFixedCellHeight(50);
        list.setFont(new Font("Serif",Font.BOLD,16));
        list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        //add(listListeners.new  CreateAccount(panel1));
        //ListListeners.CreateAccount createAccount = listListeners.new  CreateAccount(panel1);
        //add(createAccount.createAccountPanel());          
        //registering the JList listener
        list.addListSelectionListener(new ListListener());
        panel.add(list);
        add(panel,BorderLayout.WEST);
    }
    class ListListener  extends JFrame implements ListSelectionListener
    {
        public void valueChanged(ListSelectionEvent e)
        {
            int index = list.getSelectedIndex();
            if(e.getValueIsAdjusting() == false) {
                if (list.getSelectedIndex() == -1) {
                    System.out.println("No list item was selected");
                } else {
                    if(index == 0)
                    {
                        ListListeners.CreateAccount createAccount = listListeners.new  CreateAccount(panel1);
                        add(createAccount.createAccountPanel());
                        System.out.println(index);
                    }
                    else if(index == 1)
                    {
                        System.out.println(index);
                    }
                    else if(index == 2)
                    {
                        System.out.println(index);
                    }
                    else if(index == 3)
                    {
                        System.out.println(index);
                    }
                    else if(index == 4)
                    {
                        System.out.println(index);
                    }
                    else if(index == 5)
                    {
                        System.out.println(index);
                    }
                }
            }
        }
    }
    public static void main(String[] args) {
        MainGUI frame = new MainGUI();
        frame.setSize(500, 350);
        frame.setLocationRelativeTo(null);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setVisible(true);
    }    
}
This is another class with inner classes
    import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.FlowLayout;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextField;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
public class ListListeners extends JFrame {
   class CreateAccount extends JPanel
   {           
       JLabel label = new JLabel("Enter new members' name : ");
       JTextField textField = new JTextField("This is a text field");          
       JRadioButton radioButton1 = new JRadioButton();
       JRadioButton radioButton2 = new JRadioButton();
       public CreateAccount(JPanel panel)
       {
           panel.add(label);
           panel.add(textField);
           panel.add(radioButton1,radioButton2);               
           add(panel,BorderLayout.CENTER);
       }
       public JPanel createAccountPanel()
       {
           JPanel panel = new JPanel();;
           panel.add(label);
           panel.add(textField);
           panel.add(radioButton1);            
           return panel;               
       }
   }
   class BorrowBook extends JPanel
   {
       public BorrowBook(JPanel panel)
       {
           JLabel label = new JLabel("Just borrow the book and go : ");
           JTextField textField = new JTextField("This is a second text field");   
           JRadioButton radioButton1 = new JRadioButton();
           JRadioButton radioButton2 = new JRadioButton();             
           panel.add(label);
           panel.add(textField);
           panel.add(radioButton1);
           panel.add(radioButton2);            
           add(panel,BorderLayout.CENTER);
       }
   }
   class ReturnBook extends JPanel
   {
   }
   class AddBook extends JPanel
   {
   }
   class DeleteBook extends JPanel
   {
   }
   class DisplayDetails extends JPanel
   {
   }
}
 
     
    