The Wire Manager has been designed to eliminate the need for writing code when you handle events using AWT's methods, such as setText( ), getText( ). First, you wire (or connect) objects that affect one another and then use the Wire Manager to define the event that triggers the behavior.
The top two boxes represent the wired objects.
The bottom box represents the argument passed by the sender's event to the receiver's method. This argument can be Event.arg whose type and content is defined by the event, or it can consist of an object and method chosen from pull-down menus.
The Apply Changes button must be clicked for your modifications to take effect. The button is inaccessible until you begin specifying values.
The following interface allows the user to type a string in the textfield and click the button to add the string to the list box.
For the programmer, the following is involved:
When the button is clicked, an actionPerformed occurs. (If you use 1.0.2 events, an ACTION_EVENT occurs.) The event triggers the addItem method in the list box and tells the list box to get its value from the getText( ) method of the textfield. This behavior is defined by wiring the button to the list box and passing an argument that consists of the getText( )method in the textfield object.
Wire the button to the list box
and define the wire as follows:
After you click the Apply Changes button and save the file in the visual builder, the 1.1 event style generated code block looks like this:
public void init() { . . . // Initialize adaptor actionAdaptor1 = new ActionAdaptor1(); addNameButton.addActionListener(actionAdaptor1); . . . } /** * Event Adaptor. **/ ActionAdaptor1 actionAdaptor1; class ActionAdaptor1 implements java.awt.event.ActionListener { public void actionPerformed(java.awt.event.ActionEvent event) { list.addItem(String.valueOf(nameTextfield.getText())); } }
The 1.0.2 event style generated code (using ACTION_EVENT rather than actionPerformed) looks like this:
public boolean handleEvent(Event event) { . . . if (event.target == addNameButton && event.id == Event.ACTION_EVENT) { list.addItem(String.valueOf(nameTextfield.getText())); eventHandled = true; } . . . }
Cosmo Code handles any event you specify in the builder through the Wire Manager. In all cases, the code returns false to allow other objects to process the event.
Guide to the Cosmo Code Development Environment
12-96*530