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 either Java Swing or Android. Regardless of which platform you choose, you will get practice using event-driven programming and the model-view-controller (MVC) design pattern.

Below, you will find instructions that apply to both platforms followed by instructions specific to Swing GUIs and instructions specific to Android GUIs.

Note: You are expected to fix any bugs from HW8 that affect the correctness or performance of your application in HW9; however, you are not required to fix code quality/organization issues in your HW8 code. Your HW9 code should be well-written and well-organized, but we will not double-count for MVC-related style issues caused by design choices from HW8. As always, you must make sure that your HW8 tests continue to pass.

General Requirements

This assignment is deliberately open-ended: the exact appearance and functionality of your GUI are up to you. The only requirements are documented below.

Your GUI will be a new View and Controller for your CampusPaths application. Ideally, you should not have to make any changes to your HW8 model classes in order to implement the required features below — you already implemented all the Model functionality that you need. (For new features, though, you could find that you want to extend the model. That is just fine.) If you find that you need to make any small changes, though, you may do so. In the file hw9/answers.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 HW8 to create a more general and reusable Model. If you make no changes, this file should just say “None”.

Required features

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

Optional 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 a working solution, you can always revert to that version later on.

Here are a few ideas for additional features:

List any additional features you implemented, if any, in hw9/answers.txt. Additional features must not mask or replace any of the required features. Extra credit will be awarded for interesting or useful functionality that shows considerable effort.

Documentation

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

Testing

Writing automated tests for GUIs is important, but it 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. (You are free to use the same approach when testing it yourself.)

User testing is a great way to verify that your interface is easy to use. Show your GUI to your friend. Can they can figure out how to use it without directions from you? If not, you may need to redesign the GUI to make it easier to use.

Grading Criteria

For the most part, 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 design that is genuinely confusing or hard to use (at our discretion) will not receive full credit. For example, we will deduct points if we can't easily figure out how to select the two buildings, if it's hard to see the selected path, 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.

Advice

Whichever platform you use for your GUI, if the platform is new to you, it is probably well worth your time to do some tutorials, read some example code, and generally get comfortable with programming in that platform before diving into the assignment. Take it from your peers: in the past, many students who choose the latter approach have reported to us afterward that they wish they had chosen the former.

Swing Requirements

References

In addition to the lecture slides and demos, Oracle's Swing and 2D 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.

Implementation

Write your GUI with a main class in CampusPathsMain.java.

We will run your program as follows:

  cd [PathToYourCse331Project]/cse331/src/hw9
  ant build
  cd ../..
  java -cp bin hw9.CampusPathsMain

This will launch Java and invoke the main method of CampusPathsMain. That method should launch your GUI.

As usual, your program should look for files using relative filenames starting with src. (As you can see from the commands above, we will be running the application from the cse331 directory, which contains the src directory.)

Additional Requirements

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 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.

Hints

You may choose to make your window resizable, but this is not required. If you do use a fixed size, however, make sure it is large enough to be readable on a monitor with resolution 1024x768.

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 discussed in section.

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, commit, and push the following files to your GitLab repository:

Additionally, be sure to commit and push any updates you make to your HW8 files.

When you have committed and pushed all of your changes and are done with the assignment, you should create a git tag in your repository named hw9-final and push that tag to your repository. Once you have committed and pushed that tag, your assignment has been submitted and the staff will grade the files in your repository that are labeled with that tag.

Finally, remember to create a new clone of your repository and 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).

Android Requirements

References

Our development guide describes, in great detail, how to set up an Android project and how to create a simple GUI with all of the components that you will need for this assignment. After following the described steps, you should have all of the information needed to complete the assignment.

Your Android application will need to use your classes (in particular, your model class) from HW8. The easiest way to use these in Android is to create a jar file containing the compiled class files and to add that jar as a library in your Android project. See below for a discussion of how to create such a jar.

For more general information about writing Android applications, see the official documentation.

Creating a HW8 Jar

Android only supports Java 7, not Java 8, so we will need to create a jar that contains your HW8 classes compiled for version 7 of Java.

It is possible to do this using Eclipse. This guide describes how to do that by installing Java 7 on your local machine and configuring Eclipse to use it.

Alternatively, you can compile your HW8 classes for Java 7 on attu without any additional software installation. In order to do that, log into attu and run the following commands:

cd ~/
mkdir temp   # or some other scratch directory name
cd temp
git clone git@gitlab.cs.washington.edu:cse331-17au-students/cse331-17au-YourCSENetID.git
cd cse331-17au-YourCSENetID/cse331
ant -f build-android.xml clean build build-jar

The last command will build HW5-8 using Java 7 and then package all of the resulting .class files into a jar. If you type ls, you should see a file called cse331-hws.jar in the current directory on attu.

To copy this jar to your local machine, run the command prompt on your local machine and type the following command:

scp attu.cs.washington.edu:temp/cse331-17au-YourCSENetID/cse331/cse331-hws.jar .

Windows users: Replace scp above with pscp. The latter is a program that is included with PuTTY. If the command is not recognized, double check that PuTTY is installed. If PuTTY is installed and the command is still not found, try replacing pscp with the full path C:\Program Files (x86)\PuTTY\pscp.exe

The file cse331-hws.jar should now be on your local machine, in your home directory. (Typing pwd in the command prompt will print out the full path of that directory.)

Additional Requirements

Make sure that your Android application runs correctly on the default virtual device, Nexus 5X API 26 x86. If you have an Android phone, you are encouraged to also test out the application on your phone; however, we will test your application using the default virtual device mentioned above, so you must make sure that it runs properly there.

What to Turn In

Commit and push to your gitlab repository any changes you made to your HW8 classes. If you made any changes, include a description of them in hw9/answers.txt and be sure to tag the final version of all those files with the hw9-final tag, which you must also push to your repository.

Since your Android code will not compile outside of Android studio, it does not make sense to commit it into your repository in the usual manner. Instead, you will turn it in via the catalyst drop box. Create a zip file of your entire project folder (this should be a subdirectory of the AndroidStudioProjects folder) and put that in the drop box for HW9.

To test your assignment, we will import your Android code using the zip file and then run it on the default virtual device.