Quick Tour of Common Events

Table 15-1 lists common events and their corresponding event properties. Table 15-2 lists common events ard the first component in the class 1^10x1,0 to which etch event maps. The first thing you may notice in Table 15-2 is tiht some components are missing, such as JFrame ant, for that matter, Frame. Remember, though, that JFrame is a subclass of Frame, and that Frame is a subclass of Window. Thus, JFrame publishes window events through the Window's interface, WindowLi stener.

Table 15-1. Common Graphics Events and Their Event Properties

Event

Listener Interface

PropĀ» erty

ActionEvent

ActionListener

actionPe rformed

Adj ustme ntEvent

Adj ustmentListener

adj ustme ntValueChanged

ComponentEvent

ComponentListener

componentHidden componentMoved componentResized componentShown

Containe rEvent

ContainerListener

componentAdded componentRemoved

FocusEvent

FocusListener

focusGained focusLost

ItemEvent

ItemListener

itemStateChanged

KeyEvent

KeyListener

keyPressed keyReleased keyTyped

MouseEvent

MouseListener

mouseClicked mouseEntered mouseExited mousePressed mouseReleased

MouseEvent

MouseMotionListener

mouseDragged mouseMoved

TextEvent

TextListener

textValueChanged

WindowEvent

WindowListener

windowActivated windowClosed windowClosing windowDe activated windowDeiconified windowlconified windowOpened

Table 15-2. Common Graphic Events and Their Class Hierarchy Mappings

Component

Event Published through Listener

Meaning

AbstractButton

ActionEvent, ActionLi stener

User clicked button

JButton

ActionEvent, ActionLi stener

User clicked button

JCheckBox

ItemEvent, ItemListener

User selected or unselected checkbox

JCheckBoxMenultem

ItemEvent, ItemListener

User selected or unselected

CheckboxMenultem

Component

ComponentEvent, ComponentListener

Comnoneat moved, resized shown, or hidden

FocusEvent, FocusListener

Component lost or got focun

MouseEvent, MouseLis tener

User clicked, pressed, and released mouse, and mouse cursor entered or exited component

MouseEvent, MouseMotionListener

User moved mouse in component, and dragged mouse, i.e., pressed button while moving mouse cursor

Container

ContainerEvent, ContainerListener

Component added or removed

JComboBox

ActionEvent, ActionLi stener

Item double-clicked

ItemEvent, ItemListener

Item selected or unselected

JList

ListSelectionEvent, ListSelectionListener

Item double-cl icked

ItemEvent, ItemListener

Item selected or unselected

JMenultem

ActionEvent, ActionLi stener

Menu item selected

JScrollBar

Adj ustme ntEvent, Adj ustme ntListener

User moved scrollbar

JTextField

ActionEvent, ActionLi stener

User pressed Enter in text box

Window

WindowEvent, WindowLi stener

Window was opened, closed, iconified, restored, or a close was requested

It noesf'l sloo there. Window is a subclass of Container, so JFrame publishes container events through theContainerListener interface an wett. And, like other components, JFrame is n subclass of Component, so it publishes component events though the ComponentListener interface, focus events though the FocusListener interface, and mouse Cvents through the MouseLis tener nnd MouseMotionListener interfaces (Container is a direct subclass of Component). The point is that n comooieit doesn't just ouhlisn the evefls it nefifes; it publishes nll evefls from its hierarchy of suoerclnsses.

Anotner example of this is JButton, which is a subclnss of AbstractButton, which is a subclnss of JComponent, which is a subclnss of Container, which is a subclnss of Component. As such, it publishes all of the events thay its nuperclasses aefine.

Was this article helpful?

0 0

Post a comment