Adding JFileChooser beans to the free-form surface

Now that you have added the new buttons, the next step is to add file dialog beans for opening files and saving files. Later, you will use these file dialog beans to obtain a file selection and provide parameters to the readToDoFile and writeToDoFile methods.

These file dialog beans are preview beans for Swing that are not part of the Java Foundation Classes. Note that the Java Foundation Classes (JFC) present these file dialogs in a platform-independent representation as shown below:

tfiledl2.gif (5464 bytes)

In the finished To-Do List program, a file dialog appears when a user selects the Open To-Do File or Save To-Do File button. In the file dialogs, the user specifies the name of the file to open or save.

To add the file dialog beans:

  1. Select the JFrame bean from the palette.
    tjframic.GIF (216 bytes)
  2. Add the JFrame bean to the right side of the applet area, that is, outside of the gray area. Add a second JFrame bean below JFrame1. Select both of them and open the Property window to change the layout to BorderLayout.
  3. Select Choose Bean from the palette.
    tchoosbn.GIF (433 bytes)
  4. When the Choose Bean window appears, select Browse to specify the  com.sun.java.swing.preview.JFileChooser class. Click OK. Place the JFileChooser bean (which is the file dialog itself) inside JFrame1.
  5. Add a second JFileChooser dialog bean inside JFrame2.

Your free-form surface should look similar to the one below.

t3partsv.gif (12138 bytes)

Save the current state of your work in the Visual Composition Editor by selecting Save Bean from the Bean menu.

Note:
The exact positions of the file dialog beans do not affect the interface of the finished program. However, it will be easier for you to follow the instructions in the following sections for connecting beans if you line up these beans according to the instructions in this section.