GUI Changes: The AWT Grows Up |
Item events are generated by components that implement theItemSelectable
interface. These are components that maintain state -- generally on/off state for one or more items. The 1.1 AWT components that generate item events are checkboxes, checkbox menu items, choices, and lists.Item Event Methods
TheItemListener
interface has just one method, so it has no corresponding adapter class. Here's the method:
void itemStateChanged(ItemEvent)
- Called by the AWT just after a state change in the listened-to component.
Examples of Handling Item Events
The following applet demonstrates item events. [describe applet][applet goes here]
Try this:
- Do something.
You can find the applet's code [nowhere yet]. Here is the applet's item event handling code:
[code goes here]You can find more examples of item listeners in the following sections: [LIST GOES HERE]
The
ItemEvent
ClassEach item event method has a single parameter: anItemEvent
object. TheItemEvent
class defines the following handy methods:
Object getItem()
- Returns the component-specific
Object
associated with the item whose state changed. Often this is aString
containing the text on the selected item. Other possibilities might be anImage
or an object with no visual representation.ItemSelectable getItemSelectable()
- Returns the component that generated the item event.
int getStateChange()
- Returns the new state of the item. The
ItemEvent
class defines two states:SELECTED
andDESELECTED
.
GUI Changes: The AWT Grows Up |