Attaching Event-Handling Code to a Component Event

Using the Events page of the Inspector, you can attach handlers to component events and delete existing event handlers.

To attach event-handling code to a component event:

  1. Select the component in the Java Visual Editor or in the Structure window.

  2. In the Property Inspector, select the Events tab to display the Events for that component and click the desired event value field.

  3. Type the stub name of the event into the event value field and press Enter to create an event-handling method stub in the source code with the supplied name.

    JDeveloper creates an event handler with the new name and switches to that event handler in the source code. JDeveloper also inserts some additional code into your class, called an Adapter, to make the connection from the event to your event handling method.

  4. Inside the stub of the event handler write the code that specifies the response to that component event.

    Note:To find out what methods and events a component supports, right-click that component in the Code Editor and choose Go to Declaration to open the class in the Code Editor. You can also right-click the component and choose Browse Javadoc to view the documentation for that class.

To quickly create an event handler for a component's default event:

  1. Select a component on the Component Palette and add it to your UI.

  2. Double-click the component in the Java Visual Editor. An event stub is created and focus switches to that event handler in the source code.

  3. Add the necessary code to the event handler to complete it.

Note:The default event is defined by beanInfo , or as actionPerformed if none was specified.