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:

  1. Show the file dialog.
  2. Dispose of the file dialog.
  3. 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

  1. Select the Save To-Do File button and click mouse button 2. Select Connect and then actionPerformed from the pop-up menu that appears.
  2. 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.
  3. 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:

tconn5vc.gif (13716 bytes)

Now you are ready to make the connection that invokes writeToDoFile.

Create the connection to invoke writeToDoFile

  1. Select the Save To-Do File button and click mouse button 2. Select Connect and then actionPerformed from the pop-up menu that appears.
  2. Click mouse button 2 on the the free-form surface. From the pop-up menu that appears, select Event to Code.
  3. 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:
  4. To specify the file name:
  5. There is still one parameter required before the connection is complete. To specify the DefaultListModel object:
  6. The free-form surface should look like this:

    tconn6vc.gif (14279 bytes)

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.