Copyright (c) SEMM NL All rights reserved.
Author : Paul Hamaker. Part of JavaLessons.com
For manipulating a JList's contents we can use this.
JList can't scroll.
Allow one line selection only.
When a JList line is selected, this method is called ...
and the line number chosen is determined.
First line is zero.
registers this event listener,
so this method will be called.
Selected line number.
It's common practice to postpone getting the selected index, until a button is clicked, for example. In that case the class doesn't have to be an Item listener or a ListSelectionListener !
JList's getSelectedIndex returns -1 if the user hasn't selected a line yet. (Doesn't apply to this example)