Connecting the Save To-Do File button
You are now ready to make the final connections from the Save To-Do File button.
The To-Do File program should perform the following actions when the Save To-Do File
button is selected:
- Show the file dialog.
- Dispose of the file dialog.
- Invoke the writeToDoFile method to write the list of items in the To-Do list to a
file that is selected in the file dialog.
You implement actions 1 and 2 by making connections between the Save To-Do File
button and the Save JFileChooser dialog bean. You have already implemented action 3 by
making the connection between the Save To-Do File button and the readToDoFile method.
As you complete the connections listed in this section, you may notice that they are
very similar to the connections you made from the Open To-Do File button.
Create the connection to
show and dispose of the save file dialog
- Select the Save 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 JFileChooser2. From the pop-up menu that appears, select Connectable
Features. Choose Method from the End connection to window. Select showSaveDialog(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-form surface should look like this:

Now you are ready to make the connection that invokes writeToDoFile.
Create the connection to
invoke writeToDoFile
- Select the Save To-Do File button and click mouse button 2. Select Connect
and then actionPerformed from the pop-up menu that appears.
- Click mouse button 2 on the the free-form surface. From the pop-up menu that appears,
select Event to Code.
- In the Event to Code window, select writeToDoFile(java.io.File, java.io.File,
com.sun.java.swing.DefaultList Model). The connection that appears is incomplete
because writeToDoFile 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 writeToDoFile when you created it as a method in the ToDoList class.
- Move the mouse pointer to FileChooser2 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.
- To specify the file name:
- Select the connection between the Save To-Do File button and the writeToDoFile
method and click mouse button 2.
- Select Connect and then fileName from the pop-up menu that appears.
- Click mouse button 1 on FileChooser2. 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 required before the connection is complete. To specify the
DefaultListModel object:
- Select the connection between the Save To-Do File button and the writeToDoFile
method; click mouse button 2.
- Select Connect 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.
- The free-form surface should look like this:

Congratulations! You have completed all the connections from the Save To-Do File
button. Your To-Do File program is complete and you are ready to test it.
