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:
-
Select the component in the Java Visual Editor or in the Structure
window.
-
In the Property Inspector, select the Events
tab to display the Events for that component and click the desired event
value field.
-
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.
-
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:
-
Select a component on the Component Palette and add it to your UI.
-
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.
-
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.
Copyright © 1997, 2004, Oracle. All rights reserved.