[an error occurred while processing this directive]
[an error occurred while processing this directive]

PS1: Java Swing Warmup

Due at 5:00pm, Tuesday, February 19th, 2008, by email submission only.

As a warmup for the programming assignments in this course, this problem set asks you to build a small user interface that searches a list of words. We provide a backend class that does the heavy lifting (actually loading the word list and searching it). We also specify the design of the user interface. Your job is to implement it using the Java Swing user interface toolkit.

To do this assignment, you'll need to know how to:

If any of these topics are new to you, or you want to brush up on them, here are some sources that you may find helpful: You might also find the Eclipse IDE, downloadable here, a convenient Java development environment.

Provided Resources

We provide you with the following:

Feel free to change these classes as you see fit.

Problem (70%)

You should build an interface that looks like this:

The interface should have the same layout as shown above and there should be margins between widgets. When the program is first run, the list box should display the word list we gave you. (Hint: this word list should be accessed as a resource, not as a file, because you will have to pack it in your jar file to hand it in. See WordList.main() for an example showing how to find the words list as a resource. The Java documentation has more about resources.)

The Find text field contains the user's query. When the query is blank, the list box displays the entire word list, as shown above. Whenever the query changes, the list box immediately updates to display all words that contain the query text:

The list box should update constantly as the user types. Pressing Enter should not be necessary. (Hint: this requires you to use a listener that receives every change to the text field; see the JTextField class overview for a hint about which listener to use.)

If none of the words contain the query, the list box should be empty:

The Clear button should clear the query field, restoring the list box to displaying all words again:

The window should be resizable, with all extra space going to the query field and the list box:

(Hint: although this layout isn't hard to create with the standard Java layout managers, you might find ClearThought's TableLayout more fun to use.)

Finally, there should be a File menu with two options:

File/Open should pop up a JFileChooser dialog box prompting the user to select a file. The words in the selected file should become the new word list. This file should be opened like a regular file from the user's filesystem --- it is not a resource like the default word list that your program loads at startup time.

File/Exit should end the program. Closing the Word Finder window should also end the program.

Questions (30%)

Answer the following questions in a readme.txt file included in your handin.

  1. Your interface provides incremental search, since it updates immediately as the user's query changes. An alternative approach would require the user to submit the query explicitly, by pressing Enter or clicking a button with the mouse. This approach is sometimes called delimited search, because an explicit action is required to delimit the end of the query. Give some reasons why incremental search might be more usable than delimited search.
  2. WordList, the backend class that does the searching, is optimized for delimited search, not incremental search. Explain why. Hint: suppose the list has N words and the user enters an m-letter query. How much work would WordList have to do for a delimited search interface? How much for an incremental search interface?
  3. How could you change WordList to improve its performance for incremental search?
  4. What does this example suggest about how the backend implementation should be involved in the iterative design process?

Going Further

This interface is a starting point for a crossword puzzle dictionary. If you found this assignment easy and you're inclined to go further, here are some ideas for optional improvements:

What to Hand In

Package your completed assignment as a jar file. Your jar file must contain:

The Java tutorial has a section about jar files that explains how to create a jar file and define its manifest file. If you're using Eclipse, you can create a jar file from your project using File/Export. The Export wizard offers options for including source files, readme and other resources, and specifying the Main-Class for your jar's manifest.

If your program depends on any third-party libraries, you have two choices:

Before you submit your solution, put all the jar files you plan to submit in an empty directory and make sure you can run it:
java -jar yourfile.jar

Submit your solution by email (with all required jar files attached) to 6831handin@csail.mit.edu and include PS1 in the subject line.

[an error occurred while processing this directive]