The event can be triggered by the user, or the code can be used to actively set the event occurrence. For example, setSelected ()
Java. awt. event
| Listener Interface |
Event Type |
Adapter class |
| ComponentListener |
|
|
| ContainerListener |
|
|
| FocusListener |
|
|
| KeyListener |
|
|
| MouseListener |
|
|
| MouseMotionListener |
|
|
| WindowListener |
|
|
All event objects are subclasses of java. util. EventObject. The getSource method is provided to return references to event objects.
AWTEvent.
1. ChangeEvent is a lightweight event that can be used with a JSlider object or other. Its overload method is stateChanged ().
2. ComponentEvent, called when the component itself changes.
| ComponentListener method call |
ID value in ComponentEvent |
The component Status of the trigger event changes. |
| ComponentHidden () |
COMPONENT_HIDDEN |
Hide |
| CompoentShown () |
" |
" |
| ComponentMoved () |
" |
" |
| ComponentResized () |
"" |
"" |
3. FocusEvent
| Call the FocusListener Method |
|
|
| FocusGained () |
|
|
| FocusLost () |
|
|
4. InputEvent.
4.1 KeyListener
KeyPressed (), keyReleased (), keyTyped () (input character)
4.2 MouseEvent
MouseClicked () click the mouse, mouseEntered () cursor enters the component area, mouseExited () cursor leaves the component area, mousePressed () press the mouse, mouseReleased () Open the mouse
4.3 MouseMotionListenr:
MouseMoved () move the cursor over the component, mouseDragged () Press and hold the mouse and move the cursor
5. InputMethodEvent for handwriting and Voice Input
6. change notifications associated with HierarchyEvent () and HierarchyListener, HirerarchyBoundsListener, and component levels.
7. The ContainerEvent container monitors the addition and deletion components.
ComponentAdded (), componentRemoved ()
8. generate an event in the window. Define wevent
| WindowListener method call |
The component Status of the trigger event changes. |
|
| WindowActivated () |
Become activity window, that is, stack top window |
|
| WindowClosing () |
Request to close the operation. Note that you must first setdefaclocloseoperation (DO_NOTHING_ON_CLOSE) |
|
| WindowDeactivated () |
|
|
| WindowDeiconified () |
Remove icons, that is, cancel the minimum restoration. |
|
| Using wiconified () |
Minimize windows |
|
| WindowOpened () |
First display |
|
| Closed () |
Closing a window is equivalent to dispose (). Closing a window and releasing related resources are different from hiding a window. |
|
9. AbstractButton is the parent class of many common swing components, including (JButton, JToggleButton, JCheckBox, JRadioButton, JMenu, JMenuItem, JRadioButtonMenuItem, JCheckBoxMenuItem)
Each AbstractButtonAbstractButton subclass generates an ActionEvent, ChangeEvent, and ItemEvent ().
Each instance of AbstractButton maintains several different attributes: Pressed, true mark is pressing the button. armed, true indicates that the button is activated when the mouse button is released. enabled: indicates whether the button status can be changed. rolover: true indicates that the button is Enabled .. selected, whether to select.
9.1.ActionEvent is used for buttons, click, text enter, etc.
Actionreceivmed (),
9.2 ItemSelectable, ItemEvent.
ItemStateChanged (),
The ItemEvent class defines a getStateChanged () method and returns an integer. The value can be SELECTED or DESELECTED.
10. MenuDragMouseEvet generated in JMenuItem
MenuKeyEvent
11. MenuEvent generated in JMenu.
MenuCanceled (), menuDeselected (), menuSelected ()
12. events generated by JTextCompoentComponent (JTextArea, JTextPane, JTextField, JEditorPane) (insert point event, select table event in text, etc)
12.1CaretEvent and CaretListener. two methods are provided. getDot () identifies the insertion point position of the text component, and getMark () identifies the start point of the selected block .. note: The starting point value may be equal to or greater than or less than the insertion point position. If the starting point value is equal to the insertion point position, no text is selected.
CaretUpdate ()
12.2.JTextField can register ActionListener for listening to the enter key,
12.3JEditorPane. different types of text (such as RTF and HTML documents) can be displayed)
When a hyperlink is embedded in JEditorPane, the cursor enters or leaves, or an event HyperlinkEvent is generated when the hyperlink is clicked. hyperlinkUpdate (). hyperlinkEvent uses getEventType () to return an internal class EventType instance reference. This reference is one of three static instances of EventType, used to identify activation, one by one.
For example, if (event. getEventType () = HyperlinkEvent. eventType. ACTIVATED/ENTERED/EXITED ){}. it also provides a URL instance for getURL () to return the link. getDescription () returns the text description of the link.
13. events generated by document implementation methods.
In the swing MVC model, data is displayed in the text component, which is separated from the text component. the text component provides a data view, while javax. swing. text. document Interface Method to maintain the model (that is, the data itself ).
The Document object is obtained through the getDocument () method of the object of the JComponent subclass. Document only supports common text and has no character attribute (that is, all text fonts and colors are the same ).
The StyledDocument interface supports the formulation of character attributes. each instance of JTextComponent and its subclass has an associated Document implementation method to maintain the data displayed in the component. JTextField and JTextArea use PlainDocument by default, but they can also be specified.
DocumentEvent occurs when a document changes. note that the DocumentEvent event is a Document rather than a display component ., getDocument () returns a reference to the event source. getType () indicates the nature of the event (such as text insertion and text deletion), and getLength () and getOffset () indicate the number of characters affected by the change, and the offset at which the document changes. getChange () can be used to obtain the change information of a specific element or document component.
DocumentListener method call: changedUpdate () text style change, insertUpdate () insert, removeUpdate () Delete
13.1 input verification. The application usually needs to restrict or verify the input. (For example, text fields may only allow numbers or length restrictions)
You can override the Document Object.
13.2 UndoableEditEvent (UNDO text, redo)
Step 1: generate the javax. swing. undo. UndoManager instance and maintain relevant information.
2. Generate a request and then delegate it to UndoManager for related operations.
3. register the Dcoument of the text component as UndoableEditListener. When you receive the UndoableEditEvent, add the Edit information to UndoManager through addEdit.
UndoableEditHappened ()
UndoManager has several common methods: canUndo (), canRedo () returns a boolean value for condition determination.
14. events generated by JList
ListSelectionEvent, overridden valueChanged ()
ListDataListener
15. events generated by JComboBox (drop-down)
ActionEvent and two itemevents
16. events generated by JPopupMenu
PopupMenuEvent
17 events generated by ScrollBar
AdjustmentEvent
18. JTree-related