It's not a secret anymore!
The moose likes Beginning Java and the fly likes ActionEvent or Itemevent? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "ActionEvent or Itemevent?" Watch "ActionEvent or Itemevent?" New topic

ActionEvent or Itemevent?

Lalit Sha

Joined: Jan 11, 2001
Posts: 28
You have a user interface that shows a java.awt.List of named colors from which the user can select to set the background of an application. Which event is generated when one of the names is selected? The answer says Itemevent. Could anybody tell me why ItemEvent and not ActionEvent?
Cindy Glass
"The Hood"

Joined: Sep 29, 2000
Posts: 8521
Because a List is more complicated than a Button or some other component. When you press a Button, an event is fired and that's all that you need to know.
When you select an item from a list you need to know MORE that just that "something" happened. You need to know WHAT was selected.
List implements the ItemSelectable interface to provide this more sophisticated functionality.

"JavaRanch, where the deer and the Certified play" - David O'Meara
Bosun Bello
Ranch Hand

Joined: Nov 06, 2000
Posts: 1510
Just thought I'd add that double-clicking a list item does generate an action event.


So much trouble in the world -- Bob Marley
I agree. Here's the link:
subject: ActionEvent or Itemevent?
It's not a secret anymore!