# Tips on Using Beans Effectively

Since JDE is becoming a bean-based tool there are things you should do when you are designing applications or applets in the current version of JDE.

For highlights on groups and shadows, generated code, and events, see A Groups and Shadows Quick Start Guide.

## Customizing Component Properties

When you want to set or get a component property programmatically, you should code directly to the shadow's underlying AWT component or bean (the body) by using the `getBody` method.

Here is an example of how to set the label on an AWT component, such as a button:

         Button myButtonBody=(Button)gui.myButton.getBody();
         myButtonBody.setLabel("New Button Label");
         String theLabel=myButtonBody.getLabel();

Here is an example of how to call a method on a bean. In this example the bean is called `Pinto`.

         Pinto myPintoBody=(Pinto)gui.myPinto.getBody();
         myPintoBody.createBurrito("Hot sauce");

## Adding Operations to AWT Components and Beans

You can add events to components and beans in the following ways:

- If you want to use 1.0 events on AWT components, use the Operations dialog box.
- If you are adding behavior to beans in your application or applet, you should hook up behavior using listeners. You can add listeners in the `createGroup` method in the application's Group file. For example:

         public class Button extends Group implements ActionListener {
           ...
           private Button myButtonBody;
           public void createGroup() {
             myButtonBody=(Button)gui.myButton.getBody();
             myButtonBody.addActionListener(this);
           }

           public void actionPerformed(ActionEvent e) {
             if (e.target == myButtonBody) {
                  // code to handle the event here
             }
           }
         }

  As soon as you register a listener on a component, the operations you defined for the same component using the Operations dialog box will not operate. The reason is because the code generated for the operations are in the JDK 1.0 style events.

The Message filters in the Filter dialog box does not translate well to the JDK 1.1 event style. You should use the JDK's event listener mechanism to implement the equivalent functionality.

## Additional Information

For an overview of how beans are created and used in JDE, see Beans in JDE. The overview discusses the bean cycle from the creation of JAR files to the importation, the instantiation, and the updating of beans.

For an example of how to create and use beans in the JDE, see Tutorial Eight: Creating the Clock Project.