I am following a series of Java tutorials in an attempt to learn it. I have a question about tutorial 72.
Link: http://www.youtube.com/watch?v=9z_8yEv7nIc&featur
According to JList
javadoc for Java7 I see that indeed you have no option - the two APIs (getSelectedValuesList
and setDataList
) are unrelated.
To solve it, a simple solution would be to perform LeftList.getSelectedValuesList().toArray()
- it will provide you with an array suitable for setDataList
. Disclaimer: I don't know if this is the "correct" usage recommended by Java, but it should work.
Also, note that a deprecated API does not mean it doesn't work - if you feel you don't want to invest time in it now, you can still use the old API (like in your situation where you are doing a tutorial and not some ongoing product that will be in production for the next 10 years)
As for the 2nd question - it is a matter of taste, I prefer declaring the variables without initializing them in the class declaration and setting them with values in the constructor. It is customary to give initial values to constants (e.g. public static final String AAA = "XYZ";
)