TOC PREV NEXT INDEX



Creating the main application


You have just created a JavaBean! Now you will make a simple application which will use the traffic light.

  1. Choose the 'Composer Files' group in the Project Tree.
  2. Create a new Main Application by choosing "Main App" from the Create menu.
  3. Control-click on the new Main application file in the IDE, and then choose "Rename" from the pop-up menu that appears.
  4. Rename the newly created main application "RunTraffic".
  5. Double-click the RunTraffic icon to open the Composer.
  6. From the Layouts page of the Object Palette, choose Border.
  7. Click once in the Empty space in the Working Model. A new Border Layout appears. You will see five empty spaces, labeled North, South, East, West, and Center.
  8. Select Button from the Basic page of the Object Palette
  9. Click once in the South of the Border Layout. The button you created will be used to cycle the traffic light.
  10. Choose the 'Beans' page of the Object Palette. Your JavaBean, TrafficLight, has been automatically placed on this page.
  11. Choose TrafficLight and then click in the Center section of the Border Layout.
  12. Click in the Composer window. Change the 'ObjectName' of your bean to 'theLight'.
  13. Choose "Hide all empty panels" from the Parts menu. This is a fast way to hide the empty panels in the Working Model.

Now you will make the button change the traffic light.

  1. Press the button at the bottom of the working model. Its properties notebook will appear in the Composer.
  2. Change the 'Button text' to "Cycle Light".
  3. Choose the Listeners page from the properties notebook of the button.
  4. Select 'Listen for Action events'.
  5. A new page appears in the properties notebook, called "Action". Choose this page, and then add the following code to the actionPerformed area:
theLight.cycle();

The traffic light demo is now almost finished. You can test it out by clicking on the "Cycle Light" button a few times.

You still need to tell your program what it should do when its window is closed. In this Tutorial, the program will quit when its window is closed.

  1. Toward the top of the Composer window, find the part list Choice box and choose the first item, 'RunTraffic'.
  2. Select the 'Listeners' page.
  3. Select 'Listen for window events'. A new page appears in the properties notebook called 'Window'. Select this new page.
  4. Choose 'windowClosing' from the Choice box to the left of the Code Sourcerer button.
  5. Press the Code Sourcerer button.
  6. Choose 'Java system operations...', and press the Next button.
  7. Choose 'Exit the program with termination code', and press the Done button.

The Code Sourcerer will generate the appropriate code for the program to quit when its window is closed. If you run this from within Simplicity, Simplicity will indicate to you that the program has tried to quit by displaying a dialog.


Data Representations, Inc.
http://www.datarepresentations.com
support@datarepresentations.com
sales@datarepresentations.com
TOC PREV NEXT INDEX