Defining an Event Handler

See Also

You can define event handlers using a component's property sheet or contextual menu. You can also define an event handler using the Connection wizard.

To define an event handler using the property sheet:

  1. Select the component in the Inspector window.
  2. Click Events in the Properties window.
  3. Click the value of the desired event in the list. Initially, the value for all events is <none>. When you click the value field, <none> is replaced with the default event name.
  4. Enter the handler name in the property sheet or the Handlers dialog box:
  5. Add your code for the new event handler in the Source Editor.

To define an event handler using the contextual menu:

  1. Right-click on a form component in the Filesystems window or Inspector window.
  2. Choose Events from the contextual menu and move through the submenus to choose the event. The default name is given to the event handler. Bold menu items in the Events submenus indicate event handlers that have already been defined.
  3. Add your code for the new event handler in the Source Editor.

If multiple events are of the same type (for example, focusGained and focusLost are both of the type java.awt.event.FocusEvent), you can use the same handler for all of them. For example, you could set both focusGained and focusLost to use the button1FocusChange handler. You can also use the same handler for the same event on multiple components.

Tip You can set the style of how the code for component events and their handlers is generated. Choose Tools and choose Options. Expand the Editing node and select Form Editor Settings. Set the Listener Generation Style property. You can choose between the Anonymous Innerclasses, One Innerclass, and Main Class styles. See Configuring the Form Editor for a description of these options and other Form Editor Settings.
See Also
Managing Component Events
Removing an Event Handler
Renaming an Event Handler
Adding Multiple Handlers for One Event
Setting Events With the Connection Wizard

Legal Notices