Class 2 |
Intermediate Java 30-IT-397 |
|
Using Events
-
Events and JLists....
-
With JButtons, we used ActionEvents and ActionListeners. We use a
similiar, but different event mechanism with JLists. We use ListSelectionEvents
and ListSelectionListeners.
-
The class that you write that implements the ListSelectionListener interface
must implement method valueChaned(ListSelectionEvent evt).
-
This is the counterpart to actionPerformed in the ActionListener interface
-
It is where you put the logic to be performed when an event happens.
-
The ListSelectionEvent object has a method, boolean isAdjusting().
This will return true when the event is generated by clicking down on the
mouse, and false when the event is generated by releasing the mouse button
and making the selection final.
-
Most often, you'll be interested in events when isAdjusting() returns false.
But you might want to issue a warning or do some type of validation that
prevents selection when isAdjusting() returns false.
-
This is fairly similar to ActionEvents with JButtons. And the good
news is, Forte'/NetBeans will do a lot of work for us.
Now that we have the events, we can look at getting
selected values from the JList.

Created by: Brandan Jones
December 17, 2001