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:

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

  1. 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.
  2. 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.
  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-from surface should look like this:

tconnOvc.GIF (12781 bytes)

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

  1. Select the Open 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 the free-form surface and select Event to Code.
  3. 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:
  4. You have specified one of the parameters, but the connection is still not complete. To specify the file name:
  5. There is still one parameter to specify before the connection is complete: the List object.
  6. The free-form surface should look like this:

    tconn2vc.gif (13243 bytes)

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.