8.20.1.5 Step 5: Creating connection between beans

Once the components are layed out, our next step is to setup connections between the components. When you click one button, some text has to be printed in the text area. To achieve this the button and the text area must interact. i.e. you must write the connection code. This can be done by right clicking on the component that would be the source of the event and invoking any one of the items as shown below. Here, let us create an ActionEvent between the JButton and the JTextArea.

 

 

Once you select the "actionPerformed" menu item, you will get to see a rubber band kind of representation travelling with the mouse as shown below. Move the mouse pointer on top of the destination component (JTextArea in this case) and Left-click the mouse.

 

 

This will invoke the "Interaction Wizard" which is used for creating connection classes.

 

 

The type of the connection class (Anonymous, Inner or Separate) can be selected from the second screen of the wizard.

 

 

Navigate through the wizard to the Final screen and type in the code that has to be executed inside the "actionPerformed" method as shown below. If the connection class is opted to be of type "Separate", the class is compiled when we click on the "Finish" button and errors if any are also reported.

 

 

The list of connection classes created in the screen is also displayed in the bottom left tree under the "Connections" node.

 

 

The source generated from the screen developed and the connection between beans can be viewed and edited in the source tab (JMacs editor) in the Bean Builder. You can edit the code that you had written in the interaction wizard screen in the editor also.

 

Editing the Source

 

The code related to the UI that has been developed so far is generated by the builder automatically. The code that has been generated can be viewed by selecting the "Source" tab present below the draw area.

 

The builder generated code is marked by "//<Begin..." and "//End..." tag as shown in the figure below.

 

 

Users are not advised to edit their code with in these tags. Users can plugin their code either above the "//<Begin.." tag or below the "//<End..." tag. The user code will be removed automatically during the next regeneration process of the builder when placed with in these tags.



Copyright © 2011 ZOHO Corp. All Rights Reserved.