Handout H8

Contents:

Introduction

In the previous assignment, UW Marketing commissioned you to write a route finder tool. Marketing is pleased with your initial results, but now they've asked for a graphical user interface (GUI) that visually draws routes on a map.

You will build your GUI using Java's Swing and Abstract Windowing Toolkit (AWT) libraries. In completing this assignment, you will get practice using Swing, event-driven programming, and the MVC design pattern.

When you're done, you can share your finished work with family and friends by following the instructions for creating a JAR file.

GUI Requirements

You will write a GUI and a main class to launch it named CampusPathsMain.java. This assignment is deliberately open-ended: the exact appearance and functionality of your GUI are up to you. The only requirements are documented below.

In general, we are not grading on aesthetics: it doesn't matter whether your GUI looks pretty as long as it implements the required features. Nevertheless, a genuinely confusing or unusable design will not receive full credit if it impedes us from verifying the required functionality. For example, we will deduct points if we can't easily figure out how to select the two buildings, or if we can only see the whole GUI on your 27-inch monitor. In addition, your program should be generally responsive: for instance, the GUI should not take an unusually long time to find and display paths.

Your GUI is a new View and Controller for your CampusPaths application. Ideally, you should not have to make any changes to your your Homework 7 model classes — they already implement all the Model functionality that you need. If you have to make any small changes (for instance, if your design in HW7 was poor and some model methods were too closely tied to your text view), then you may do so. As always, all tests from previous homeworks must continue to pass, so you may also need to change your HW7 View and Controller in that case. In file hw8/model-changes.txt, list any changes you made to the model. For each, write a 1-2 sentence explanation of why the change was necessary and what you could have done differently on HW7 to create a more general and reusable Model.

Window size

At startup, your GUI must fit on a screen with 1024 x 768 resolution. (You may wish to support resizing the window, but doing so is not required.)

Required features

At a minimum, your GUI must provide the following features:

Swing widgets and GUI builders

Use only components from the Swing widget set for this assignment. You are also allowed to use components from AWT, on which Swing is built, but should try to stick to Swing when possible.

Some IDEs, such as NetBeans, will let you specify the appearance and behavior of your GUI and automatically generate the code for you. You may not use these tools; you must write your GUI from scratch in Java.

Launching your GUI

The command java -cp bin hw8.CampusPathsMain should launch your GUI when run from your cse331/ project directory.

If you log into attu via ssh, but when you try to run your GUI on attu you get a message similar to

Exception in thread "AWT-EventQueue-0" java.awt.HeadlessException:
No X11 DISPLAY variable was set, but this program performed an operation which requires it.

then you need to enable X11 forwarding for your ssh session. If you are are using Linux, this can be done using the -X switch when starting ssh:

ssh -X YourUserName@attu.cs.washington.edu

If you normally use Windows, the most straightforward option is simply to log onto one of the Linux workstations in the basement labs. Alternatively, you can obtain special software to enable X11 forwarding on Windows. One free option is Xming used with PuTTY. After installing Xming, launch PuTTY, select "Enable X11 forwarding" under Connection >> SSH >> X11, and log in as normal. Please note that the course staff does not officially provide support for enabling X11 on Windows.

Optional Extra Features

We encourage you to get creative with both the appearance and functionality of your GUI! If you do, make sure to get a basic GUI working and commit it to your repository before experimenting. Swing can be finicky, and seemingly simple UI improvements often become big time sinks. If you've committed your working solution, you can always "roll back" to that revision later.

If you want an extra challenge, you are encouraged to additional features. Here are a few ideas:

List any additional features you implemented, if any, in hw8/extra.txt. You must commit a hw8/extra.txt file, even if it simply contains "None". Additional features must not mask or replace any of the required features.

Small amounts of extra credit may be awarded for interesting or useful functionality that shows considerable effort. Extra credit will not be awarded for pure "eye candy," such as changing the font and color of buttons or adding a border. Extra credit will be applied to final grades only after we have ranked the students in the class and assigned a GPA; thus, it will not lower your grade if you choose not to work on optional features, but may raise your grade slightly if you do.

Writing automated tests for GUIs is difficult and usually involves special frameworks that are beyond the scope of this course. For this reason, you are not required to write unit tests or a test driver. We will test your solution by running your main program.

We may demo some of the most impressive GUIs on the last day of lecture. If you would like your GUI to be considered, please email cse331-staff@cs.washington.edu by 11pm May 31st (the non-late-day deadline). In your email, state your CSENetID and whether you prefer to be anonymous or credited.

Reflection [1 point]

Please answer the following questions in a file named reflection.txt in your answers/ directory.

  1. How many hours did you spend on each problem of this assignment? (Only include time when you are completely focused on CSE 331. For example, if you worked an hour in your noisy dorm lounge, or you were periodically reading email or IMs, estimate the amount of time you actually spent on CSE 331 during that hour.)
  2. In retrospect, what could you have done better to reduce the time you spent solving this assignment?
  3. What could the CSE 331 staff have done better to improve your learning experience in this assignment?
  4. What do you know now that you wish you had known before beginning the assignment?

Collaboration [1 point]

Please answer the following questions in a file named collaboration.txt in your answers/ directory.

The standard collaboration policy applies to this assignment.

State whether or not you collaborated with other students. If you did collaborate with other students, state their names and a brief description of how you collaborated.

Returnin

There is no returnin for this assignment.

Hints

General GUI Advice

Abstraction functions, representation invariants, and checkRep() are not required for GUI classes because they generally do not represent ADTs.

User testing is a great way to verify that your interface is as easy to use as you think it is. Show your GUI to your friend/roommate/sibling. Can they can figure out how to use it without directions from you? Also remember the design principles and guidelines for user testing from Lecture 21.

As usual, remember to practice good procedural decomposition among other best practices for style. In particular, your GUI constructor will probably be long enough that it should be broken into helper methods.

Programming With Swing

In addition to the lecture slides and demos, Oracle's Swing and 2-D Graphics tutorials are a useful resource. Also remember to use the Java API, particularly the javax.swing and java.awt packages, to see what classes and methods are available and how to use them.

To display the map and routes, you will want to write a custom component and override paintComponent(). You will use Graphics and/or Graphics2D to do the rendering, as we saw in lecture.

If you have trouble getting things to display at the correct size, make sure you have remembered to call pack() before setting your frame to be visible.

What to Turn In

You should add and commit the following files to SVN:

Additionally, be sure to commit any updates you make to your Homework 7 files.

Finally, remember to run ant validate to verify that you have submitted all files and that your code compiles and runs correctly when compiled with javac on attu (which sometimes behaves differently from the Eclipse compiler).

Errata

None yet!

Q & A

None yet!