The best way to learn about visual programming is to do it.
The following sections guide you through using VisualAge to
develop a simple or advanced To-Do List application. The simple
application allows you to add items to or remove items from the
list. The advanced application allows you to save the list for
use now or later.
Create a To-Do project and a To-Do List visual
part through the IDE SmartGuides:
- In the Project name field of the Project
SmartGuide, enter ToDoList.icc.
- On the Target Type panel, select the Add Target
button and the Target Smart Guide appears.
- In the Target name field enter ToDoList.exe.
- In the Program Type list box select IOC
application and select Next.
- On the Part Type panel, select the Create part
button and the Parts SmartGuide appears.
- In the Visual part name field, enter ToDoList
and select Next twice.
- On the Client Area panel, select ICanvas
and then OK and the new part appears in the Current
parts list of the Part Type panel.
- Select OK and the Target Type panel
appears. Select Finish and open the project in the
IDE.
In the IDE Project panel, select the Parts button. If no parts
appear in the left panel, right click in that panel and select
refresh view. When the part appears, select it and select Edit
part from the right panel and the Composition Editor opens
with the new visual part.
Change the window name to To-Do List by holding the
Alt key and clicking the pointer over the title bar. Delete the
existing text and enter the new text. To save the change, hold
shift and press enter. This is called direct edit.
After creating your new visual part, you can place parts in
the application window.
Placing a Static Text Part in the To-List Application
Window:
- Select the Data entry category, from the left
column of the parts palette.
- Select the IStaticText* icon, from the right
column of the parts palette. As you move the mouse
pointer over the free-form surface it changes to
crosshairs, indicating that the mouse pointer is loaded
with the IStaticText* part.
- Place the crosshairs in the upper-left corner of the
To-Do List application window and click mouse
button 1. A static text part appears in the window.
- As you did the window name above, direct edit the text of
the static text part to To-Do Item:.
Placing an Entry Field in the To-Do List Application
Window:
- From the Data Entry category, select the IEntryField*
icon, from the right column of the parts palette.
- Place the crosshairs beneath the first static text part
and click mouse button 1. The entry field part
appears beneath the static text part.
Placing Another Static Text Part in the To-Do List
Application Window:
- As you did with the first static text part, place the
second static text part in the To-Do List application
window.
- Change the text of the static text part to To-Do
List:
Placing a List Box in the To-Do List Application Window:
Because the to-do list consists of a list of text strings, you
will store that list in an IListBox* part. To place a list box
part in the To-Do List application window:
- Select the Lists category from the left column of
the parts palette.
- Select the IListBox* icon from the right column of
the parts palette.
- Place the crosshairs below the second static text part
and click mouse button 1. The list box part appears
beneath the second static text part.
Placing the Push Buttons in the To-Do List Application
Window:
- Select the Buttons category, from the left column
of the parts palette.
- Select the IPushButton* icon, from the right
column of the parts palette.
- Select Sticky from the bottom left side of the
parts palette area to pick up more than one part.
- Place the crosshairs below the lower-left corner of the
list box and click mouse button 1. The first push
button part appears in the window.
- Place the crosshairs to the right of the first push
button and click mouse button 1. The second push
button appears in the window.
- Deselect Sticky to unload the pointer.
- Change the text of the first push button to Add.
You may also use the direct edit technique on push
buttons.
- Change the text of the second push button to Remove.
Once you have placed all the parts that you need in the
application window, you should resize and align them.
Resizing the To-Do List Application Window:
- Select the application window by clicking mouse
button 1 on the title bar.
- Move the mouse pointer over the selection handle on the
lower-right corner of the application window.
- Press and hold mouse button 1.
- Resize the application window by dragging the mouse
pointer towards the left until it is the size you want.
You can resize the window any time during the creation
process. To size the window in only one direction, either
horizontally or vertically, hold down the Shift key while
dragging the mouse pointer.
Matching the Widths of Parts in the To-Do List Application
:
- Select the list box and drag the right bottom selection
handle to the width you want the box.
- Select the entry field.
- To select the anchor part, which is the part used
to determine placement or size, do the following:
- In OS/2, while holding down mouse button 1,
move the mouse pointer to the list box.
- In Windows, while holding down the Shift key,
select the list box.
Solid selection handles, like those on the list box,
means that the part is the anchor part. Therefore,
any sizing actions performed cause the entry field to
match the size of its anchor part, the list box.
- From the tool bar or the Tools drop-down, select Match
Width. The width of the entry field changes to match that
of the list box.
Repeat these steps with the Add and Remove push
buttons to match their widths.
Dragging and Dropping Parts in the To-Do List Application
Window:
| Note: |
The following instructions
are for moving multiple parts simultaneously. If you want
to move one part at a time, skip the first step. |
- Select all of the parts you want to drag using the
multiple parts selection technique for OS/2 or Windows
(see Selecting
Parts to review).
- Move the mouse pointer over one of the parts that you
selected to drag.
- Press and hold mouse button 2 in OS/2 or mouse
button 1 in Windows and move the mouse cursor. The
Composition Editor displays an outline of the parts that
you are dragging.
- Move the outline to the place where you want to drop the
parts and release the mouse button. The parts appear in
their new location.
Centering the Entry Field and List Box Within the To-Do
List Application Window:
- Select the entry field.
- Select the Distribute Horizontally tool, from the row of
icons on the tool bar. The Composition Editor centers the
entry field between the left and right borders of the
application window.
- Select the list box and then the entry field, making the
entry field the anchor part. Use the multiple part
selection technique you learned previously.
- Select the Align Center tool, from the row of icons on
the tool bar. The list box is centered beneath the entry
field.
Aligning the Left Edges of the Parts in the To-Do List
Application :
- Select both static text parts, the list box, and then
select the entry field, making the entry field the anchor
part.
- Select the Align Left tool, from the row of icons on the
tool bar. The first static text part is aligned even with
the left edge of the entry field.
Aligning the Top Edges of the Push Buttons in the To-Do
List Application:
- Select Add and then select Remove.
- Select the Align Top tool. The Composition Editor aligns
the Add push button even with the top of the Remove
push button.
Centering the Push Buttons in the To-Do List Application :
- Select both push buttons. You can make either push button
the anchor part.
- Press and hold mouse button 2 in OS/2 or mouse
button 1 in Windows and position the push buttons
midway between the bottom edge of the list box and the
bottom window border.
- When the push buttons are in place, release the mouse
button.
Spacing the Push Buttons in the To-Do List Application:
- Select both push buttons. You can make either push button
the anchor part.
- Select the Distribute Horizontally tool. The Composition
Editor spaces both push buttons evenly across the
application window.
You can now connect the parts so that your application can add
and remove items from the to-do list. You need to connect the
push buttons to the list box and entry field. The following steps
show you how to do this.
Connecting the Add Push Button to the To-Do List
Application List Box:
- With the mouse pointer over the Add push button,
click mouse button 2. A pop-up menu appears.
- Select Connect. A cascaded menu, called the connection
menu, of the Add push button is displayed.
- Select the buttonClickEvent feature. Selecting the
buttonClickEvent feature means that you want
something to happen whenever a user selects this push
button. The mouse pointer changes to look like a spider,
indicating that you may select another feature.
- Move the mouse pointer to the list box and click mouse
button 1. A pop-up menu appears showing the
connection menu of the list box.
- Select the addAsLast action. Selecting the addAsLast
action means that you want new items to be added to the
end of the to-do list whenever a user selects Add.
- Move the mouse pointer to the dashed connection line
between Add and the list box. A dashed line means
that the connection is incomplete. The connection is
supposed to add something to the list box when you select
Add, but you have not yet supplied what needs to
be added.
- Open the connections menu by holding down the Alt key,
clicking mouse button 2, and releasing the Alt key
immediately afterward. The pop-up menu for the connection
appears.
- Select the text parameter. Connecting the text
parameter to the entry field provides a value for the
connection line and changes its appearance from dashed to
solid.
- Move the mouse pointer over the entry field, and click
mouse button 1. The Composition Editor displays the
connection menu for the list box.
- Select the text attribute. Selecting the text
attribute here means that you want to pass the text
entered in the entry field to the text parameter
of the addAsLast action. When the addAsLast
action is called, whenever you select Add, the
text string is added to the end of the to-do list.
Connecting the Remove Push Button to the To-Do List
Application List Box:
- With the mouse pointer over the Remove push
button, hold down the Alt key and click mouse
button 2. The Composition Editor displays the
connection menu for the Remove push button.
- Select the buttonClickEvent feature.
- Move the mouse pointer to the list box and click mouse
button 1. The Composition Editor displays the
connection menu for the list box.
- Select the remove action. Selecting the remove
action means that you want your application to remove the
selected item in the to-do list whenever a user selects Remove.
Once again, the connection is incomplete.
- Move the mouse pointer to the connection between the Remove
push button and the list box.
- Hold down the Alt key and click mouse button 2. The
Composition Editor displays the connection menu for the
connection.
- Select the index parameter. Connecting the index
parameter to the list box provides a value for the
connection line and changes its appearance from dashed to
solid.
- Move the mouse pointer over the list box and click mouse
button 1. The Composition Editor displays the
connection menu for the list box.
- Select the selection attribute. Selecting the selection
attribute means that you want to pass the index of the
selected item in the list box to the index
parameter of the remove action. The remove
action uses this index to determine which item to remove
when you select Remove.
Now that you have made all of the connections, the next step
is Building and Executing Your
To-Do List Application.