I am following a series of Java tutorials trying to learn them. I have a question about textbook 72.
Link: http://www.youtube.com/watch?v=9z_8yEv7nIc&feature=relmfu
At 7:02 the video this expression is written. However, this method is deprecated in Java 1.7.
RightList.setListData(LeftList.getSelectedValues());
Eclipse returns the following error:
Object[] javax.swing.JList.getSelectedValues() getSelectedValues @Deprecated public Object[] getSelectedValues() Deprecated. As of JDK 1.7, replaced by getSelectedValuesList() Returns an array of all the selected values, in increasing order based on their indices in the list. Returns: the selected values, or an empty array if nothing is selected See Also: isSelectedIndex(int), getModel(), addListSelectionListener(javax.swing.event.ListSelectionListener)
But this returns an error: "The setListData(Object[]) in the type JList is not applicable for the arguments (List)' method setListData(Object[]) in the type JList is not applicable for the arguments (List)' .
What is the correct way to replace the above statement?
In addition, I want to take this opportunity to ask another unrelated question. Is it better to initialize variables outside the method as follows:
private JList LeftList = new JList(); private JList RightList = new JList(); private JButton Move = new JButton("Move -->"); private static String[] Items = {"Item 1", "Item 2","Item 3","Item 4","Item 5"};
Compared to (as shown in the video): Declaring variables outside the class as described above, but assigning values to them inside the method?
Is it doing better?