public class

ItemEvent

extends AWTEvent
java.lang.Object
   ↳ java.util.EventObject
     ↳ java.awt.AWTEvent
       ↳ java.awt.event.ItemEvent

Class Overview

A semantic event which indicates that an item was selected or deselected. This high-level event is generated by an ItemSelectable object (such as a List) when an item is selected or deselected by the user. The event is passed to every ItemListener object which registered to receive such events using the component's addItemListener method.

The object that implements the ItemListener interface gets this ItemEvent when the event occurs. The listener is spared the details of processing individual mouse movements and mouse clicks, and can instead process a "meaningful" (semantic) event like "item selected" or "item deselected".

Summary

Constants
int DESELECTED This state-change-value indicates that a selected item was deselected.
int ITEM_FIRST The first number in the range of ids used for item events.
int ITEM_LAST The last number in the range of ids used for item events.
int ITEM_STATE_CHANGED This event id indicates that an item's state changed.
int SELECTED This state-change value indicates that an item was selected.
[Expand]
Inherited Constants
From class java.awt.AWTEvent
[Expand]
Inherited Fields
From class java.awt.AWTEvent
From class java.util.EventObject
Public Constructors
ItemEvent(ItemSelectable source, int id, Object item, int stateChange)
Constructs an ItemEvent object.
Public Methods
Object getItem()
Returns the item affected by the event.
ItemSelectable getItemSelectable()
Returns the originator of the event.
int getStateChange()
Returns the type of state change (selected or deselected).
String paramString()
Returns a parameter string identifying this item event.
[Expand]
Inherited Methods
From class java.awt.AWTEvent
From class java.util.EventObject
From class java.lang.Object

Constants

public static final int DESELECTED

This state-change-value indicates that a selected item was deselected.

Constant Value: 2 (0x00000002)

public static final int ITEM_FIRST

The first number in the range of ids used for item events.

Constant Value: 701 (0x000002bd)

public static final int ITEM_LAST

The last number in the range of ids used for item events.

Constant Value: 701 (0x000002bd)

public static final int ITEM_STATE_CHANGED

This event id indicates that an item's state changed.

Constant Value: 701 (0x000002bd)

public static final int SELECTED

This state-change value indicates that an item was selected.

Constant Value: 1 (0x00000001)

Public Constructors

public ItemEvent (ItemSelectable source, int id, Object item, int stateChange)

Constructs an ItemEvent object.

Note that passing in an invalid id results in unspecified behavior. This method throws an IllegalArgumentException if source is null.

Parameters
source the ItemSelectable object that originated the event
id an integer that identifies the event type
item an object -- the item affected by the event
stateChange an integer that indicates whether the item was selected or deselected
Throws
IllegalArgumentException if source is null

Public Methods

public Object getItem ()

Returns the item affected by the event.

Returns
  • the item (object) that was affected by the event

public ItemSelectable getItemSelectable ()

Returns the originator of the event.

Returns
  • the ItemSelectable object that originated the event.

public int getStateChange ()

Returns the type of state change (selected or deselected).

Returns
  • an integer that indicates whether the item was selected or deselected

public String paramString ()

Returns a parameter string identifying this item event. This method is useful for event-logging and for debugging.

Returns
  • a string identifying the event and its attributes