Connecting the Open To-Do File button
Now that you have added all the new beans to the free-form surface, you are ready to
begin connecting them.
The To-Do List applet should perform the following actions when a user selects the Open
To-Do File button:
- Show the file dialog.
- Dispose of the file dialog.
- Invoke the readToDoFile method.
You implement actions 1 and 2 by making connections between the Open To-Do File
button and the JFileChooser bean for opening files. You implement action 3 by making a
connection between the Open To-Do File button and the DefaultListModel bean.
Create the connection to
show and dispose of the open file dialog
- Select the Open To-Do File button and click mouse button 2. Select Connect
and then actionPerformed from the pop-up menu that appears. The mouse
pointer changes to indicate that you are in the process of making a connection.
- Complete the connection by clicking mouse button 1 on the JFileChooser bean to the right
of the applet. From the pop-up menu that appears, select Connectable Features.
Choose Methods from the End connection to window. Select showOpenDialog(java.awt.Component).
Click OK.
- Select the connection just completed and click mouse button 2. Select Connect and
then parent from the pop-up menu. Click the frame containing the file chooser and
select this from the pop-up menu.
Now the free-from surface should look like this:

You have completed all the connections between the Open To-Do File button and
the JFileChooser that get data from a file and put it in your To-Do list. Now you are
ready to make the connection that invokes readToDoFile in the DefaultListModel
bean.
Create the connection to
invoke readToDoFile
- Select the Open To-Do File button and click mouse button 2. Select Connect
and then actionPerformed from the pop-up menu that appears.
- Click mouse button 1 on the free-form surface and select Event to Code.
- In the Event to Code window, select method readToDoFile(java.io.File, java.io.File,
com.sun.java.swing.DefaultListModel) and then select OK. The connection that
appears is incomplete because readToDoFile takes three parameters: a directory
name, a file name, and a DefaultListModel object. Begin by specifying the directory name:
- Select the connection and click mouse button 2.
- Select Connect and then dirName from the pop-up menu that appears. Notice
the selections under Connect include the names of all the parameters that you
specified for readToDoFile when you created it as a method.
- Move the mouse pointer to JFileChooser1 and click mouse button 1. Select Connectable
Features from the pop-up menu that appears.
- Choose Method from the End connection to secondary window, select getCurrentDirectory()
and then select OK.
- You have specified one of the parameters, but the connection is still not complete. To
specify the file name:
- Select the connection between the Open To-Do File button and the readToDoFile
method; click mouse button 2.
- Select Connect and then fileName from the pop-up menu that appears.
- Click mouse button 1 on JFileChooser1. Select Connectable Features from the
pop-up menu that appears.
- Choose Method from the secondary window, select getSelectedFile() and then
select OK.
- There is still one parameter to specify before the connection is complete: the List
object.
- Select the connection between the Open To-Do File button and the readToDoFile
method; click mouse button 2.
- Select Connect and then fillList from the pop-up menu that appears.
- Click mouse button 1 on the DefaultListModel bean and select this from the pop-up
menu that appears. This last connection is significant. It specifies that the
DefaultListModel bean in the user interface is the fillList parameter for readToDoFile.
In other words, the DefaultListModel bean in the interface is the DefaultListModel object
in which readToDoFile adds items as it reads the input file.
- The free-form surface should look like this:

Congratulations! You have completed all the connections from the Open To-Do File
button. Now you are ready to test the work you have done so far on the To-Do List program.
