0

Hi. I need some help. That's a snippet of the class.

public constructor ( ChooserListener callback ) {  // that's a constructor
        super();
        Loader.load();
        this.callback= callback;
        JFrame frame = new JFrame();       
        frame.getContentPane();
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.add(this);
        frame.setSize(300,330);
        frame.setVisible(true);
        
        JPanel lectures = new JPanel();
        String items [] ={BLANK,COMP,EIMC,MATH};
        JList list = new JList(items);                
        list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);        
         list.addListSelectionListener( listSelectionListener); 
         lectures.add(list);
}
ListSelectionListener listSelectionListener = new ListSelectionListener() { 
        
            public void valueChanged (ListSelectionEvent e) 
            {    // System.out.println(  listSelectionListener);
                System.out.println("Hooray"); 
             if (e.getValueIsAdjusting()== false)
                // tell(dept[deptList.getSelectedIndex()]);  
                  tell(COMP);  
             }
            };
} // the end of class

I can't understand why System.out.println("Hooray"); is not executed. Why execution bypasses that 'valueChanged' method. What's the problem?
Cheers

Edited by peter_budo: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks)

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by cale.macdonald
0

You are not attaching the list selection listener to the list. Do that and you should have your problem fixed.

Cheers

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.