Defining event handlers
To define an event handler using the property sheet:
- Select the Events tab in the form object's property sheet (either in the Component Inspector or the Properties window).
- Click on the value (it should be
<none>
) of the one of the events in the list.![]()
- Choose a name for the event by:
After you press ENTER, the code for the listener and the (empty) body of the handler method will be generated. If you do not press ENTER, your changes will be ignored.
To define an event handler using the contextual menu:
- Expand the source file's node in the Explorer and then right-click on its form object subnode.
- Choose Events and then move through the two submenus to choose the event. The default name will be given to the event.
If multiple events are of the same type (for example,
focusGained
andfocusLost
are both of typejava.awt.event.FocusEvent
), then you may use the same handler for all of them. For example, you could set bothfocusGained
andfocusLost
to use thebutton1FocusChange
handler. You can also have the same event on several components share a handler.When you enter a new name for an existing handler, the code block is automatically edited to use the new name. When you delete a name, the code block is deleted. If more than one handler uses the same name (and the same block of code), deleting a single reference to the code will not delete the code; only deleting all names will delete the corresponding code block, and a confirmation dialog box will be displayed first.
Note: If you delete an event but do not delete the event handler when prompted by the confirmation dialog box, an orphaned handler will remain in the guarded text. If you wish to delete the orphaned handler, you will have to add another event, attach it to the handler, delete that event, and then agree to delete the handler in the confirmation dialog box.
Contents | Prev | Next | Index |