Java Reference
In-Depth Information
• An inner-class object can directly access the instance variables and methods of its top-level class.
• A nested class that's static does not require an object of its top-level class and does not implicitly
have a reference to an object of the top-level class.
• Pressing Enter in a JTextField or JPasswordField generates an ActionEvent (p. 489) that can be
handled by an ActionListener (p. 489) of package java.awt.event .
JTextField method addActionListener (p. 489) registers an event handler for a text field's
ActionEvent .
• The GUI component with which the user interacts is the event source (p. 490).
•An ActionEvent object contains information about the event that just occurred, such as the event
source and the text in the text field.
ActionEvent method getSource returns a reference to the event source. ActionEvent method
getActionCommand (p. 490) returns the text the user typed in a text field or the label on a JButton .
JPasswordField method getPassword (p. 490) returns the password the user typed.
Section 12.7 Common GUI Event Types and Listener Interfaces
• Each event-object type typically has a corresponding event-listener interface that specifies one or
more event-handling methods, which must be declared in the class that implements the interface.
Section 12.8 How Event Handling Works
• When an event occurs, the GUI component with which the user interacted notifies its registered
listeners by calling each listener's appropriate event-handling method.
• Every GUI component supports several event types. When an event occurs, the event is dis-
patched (p. 494) only to the event listeners of the appropriate type.
Section 12.9 JButton
• A button is a component the user clicks to trigger an action. All the button types are subclasses
of AbstractButton (p. 495; package javax.swing ). Button labels (p. 495) typically use book-title
capitalization (p. 495).
• Command buttons (p. 495) are created with class JButton .
•A JButton can display an Icon . A JButton can also have a rollover Icon (p. 497)—an Icon that's
displayed when the user positions the mouse over the button.
•Method setRolloverIcon (p. 498) of class AbstractButton specifies the image displayed on a
button when the user positions the mouse over it.
Section 12.10 Buttons That Maintain State
• There are three Swing state button types— JToggleButton (p. 498), JCheckBox (p. 498) and
JRadioButton (p. 498).
• Classes JCheckBox and JRadioButton are subclasses of JToggleButton .
Component method setFont (p. 500) sets the component's font to a new Font object (p. 500) of
package java.awt .
•Cicking a JCheckBox causes an ItemEvent (p. 501) that can be handled by an ItemListener
( p. 501) which defines method itemStateChanged ( p. 501). Method addItemListener registers
the listener for the ItemEvent of a JCheckBox or JRadioButton object.
JCheckBox method isSelected determines whether a JCheckBox is selected.
JRadioButton s have two states—selected and not selected. Radio buttons (p. 495) normally ap-
pear as a group (p. 501) in which only one button can be selected at a time.
Search WWH ::




Custom Search