Adding Operations to Components

To add an operation to an individual component, add code to the actual body class instead of the shadow class. Edit code for the shadow class when an operation is being added to a group or subgroup.

You can add operations in the following ways:

Operations can be added to beans with the Operations dialog box or by manual coding, see the section Adding Operations to Beans.

To add an operation to a component through the Operations dialog box:

  1. Select the component in the layout.
  2. Open the attribute editor by clicking on its button in the main toolbar.
  3. Open the Operations dialog box by clicking the Edit operations button in the attribute editor.
  4. Click the Insert button to add an operation (GUI builder provides a default name, Opsnumber, for the operation; you can rename the operation by typing a name in the Op name box).

    Use the Delete button to remove operations from the list. If you accidentally delete operations, you can click Reset to reset the list to its state after the last Apply operation. There is no Undo, so you cannot reverse changes that you have applied.

  5. Click the Filter button to set the triggering event--either an event filter or a message filter.

    Filters are described in Filters. New style 1.1 events are not supported in this release. For information on new-style and old-event handling, see the JDK documentation, "Java AWT: Delegation Event Model". (You may have to reset the proxies on the Java Workshop help browser if you have difficulties reaching the Delegation Event Model.)

  6. Click the Action button to set the desired response to the trigger.
  7. Select the appropriate action type (action types are described in Actions).

    As you add more filters and actions, you can test them in the layout window. Custom actions added in the Action dialog box are available only when running the application.

  8. Save the operation settings by clicking OK in the Operations dialog box.
To add an operation directly to the source file:
  1. Create the layout with GUI builder.
  2. Save the layout and generate a .gui file.
  3. Click on the Open button in the Edit/Debug toolbar and select the project.java file.
  4. Add code to the "group" file in the handleEvent() method. For example:
       public boolean handleEvent(Message msg, Event evt) {
    
        if (evt.target == gui.button1.getBody() &&
    	evt.id == Event.ACTION_EVENT) {
            System.out.println("got a click on button1");
    	return true;
        }
    
        return super.handleEvent(msg, evt);
      }
    
To add an operation using both methods:

Adding Operations to Beans

Adding operations to a bean with the Operations dialog box is done exactly as described at the beginning of this page. Code generated for the operations are in the JDK 1.0.2 propagation-style events. To use new-style event handling, you must implement the code manually.

When you add operations to a bean using the Operations dialog box, the events fired by the bean do not show up on the list of event filters. You must manually add code to register listeners for those events.

To register listeners:

  1. Add a listener interface to the implementation line.
  2. Add a listener function to the group.
For example,
public class MyApp extends Group implements ActionListener{
  ...

  protected void createGroup() { 
      // make the group an action listener of the bean
      Bean body = (Bean)gui.bean1.getBody();
      body.addActionListener(this);

  ...

   public void actionPerformed(ActionEvent e) {
     ...
   }
}

Getting Bean Information

When you are adding operations, you can find out what method can be called for a particular bean with the Bean Info dialog box. The Bean Info dialog box provides you with the following information about a selected bean:

To look up the specific features of a bean:

  1. Select the bean in the layout window.
  2. Choose GUI -> Bean Info on Selected Component.
  3. Click the Properties, Events, or Methods tab.

See also:

What Is a Component Operation?
Laying Out GUI Interfaces
Generating Java Source Code
GUI Builder Runtime Classes
What Are Groups and Shadows?
More On Groups and Shadows

Visual Java GUI Builder API Documentation
Visual Java GUI Builder Runtime Packages
Class Hierarchy
Index of All Fields and Methods