CSCI 2600 Homework 9 Campus Paths GUI




5/5 - (1 vote)


In Homework 7, you wrote a program that found shortest routes between buildings on the RPI Campus. Now we are asking for a graphical user interface (GUI) that visually draws routes.

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 (Observer) design pattern.

You are expected to fix any bugs from Homework 7 that affect the correctness or performance of your application in Homework 9. Further, your Homework 9 should use the model you created in Homework 7. This may require that you modify your Homework 7 code, that is ok, but be sure that Homework 7 continues to pass all tests!

There is no auto-grading on this assignment. However, you still must submit through Submitty.

GUI Requirements

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

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 which is genuinely confusing or hard to use (at our discretion) may 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 a 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 Campus Paths application. Ideally, you should not have to make any changes to 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 Homework 7 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 Homework 7 View and Controller in that case. In file hw9/answers/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 Homework 7 to create a more general and reusable Model. If you made no changes, write “None” for this section.

Window size

At startup, your GUI must fit and be usable on a screen with a 1024 x 768 resolution. (You may wish to support resizing the window, but doing so is not required.) Most computers provide a way to change the screen resolution, which you can use for testing.

Required features

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

  • Load the map data from hw7/data/RPI_map_data_Edges.csv and hw7/data/RPI_map_data_Nodes.csv on startup. (This should be in your model, not your view. There is no need to duplicate files; load them from the hw7 directory.)
  • Display the map of the RPI campus. You may remove the part at the bottom with the building names if you need. (Important note: download the map here and save it into your hw9/data directory: hw9/data/RPI_campus_map_2010_extra_nodes_edges.png. DO NOT commit the map as the large file may break the limit on repo size. When testing, we will copy the map into your hw9/data directory under name RPI_campus_map_2010_extra_nodes_edges.png.)
  • Allow the user to select two buildings for finding a route. You might use free-text entry, dropdown menus, selection with the mouse, or some other approach.
  • Mark the selected buildings and/or path endpoints on the map.
  • Draw the shortest route between the selected buildings on the map. Ideally the map should automatically be zoomed in or out when a route is drawn, so that the route is almost as large as possible while still fitting in the window, but this is not required.
  • Allow the user to reset the GUI by clicking a reset button. This button should clear all markings on the map and all other controls (such as building selectors), setting the GUI back to its initial state.
  • Operate robustly: No matter what the user does, your program should never allow an exception message to bubble up to the console window, and your GUI should never crash or reach a buggy/invalid state.

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

We will launch your GUI from Run As –> Java Application.

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 implement additional features. Here are a few ideas:

  • As the window is resized, make the map shrink or grow to fit the window.
  • Maintain the proportions of the map so that it zooms in on a route without becoming distorted.
  • Place the map in a ScrollPane so it can be displayed full-size. When displaying a route or buildings, jump to that spot on the map to resize if needed. (Hint: you probably need to override getPreferredSize() in your “canvas” class for scrolling to work.)
  • Allow the user to select the endpoints of a path by clicking with the mouse on the map.
  • Allow the user to drag the map with the mouse to change the portion that is shown.
  • Add zoom buttons, possibly with a way to recenter the image for zooming if a hand is not available to drag it (e.g., mouse double click).

List any additional features you implemented, if any, in hw9/answers/extra.txt. You must commit a hw9/answers/extra.txt file, even if it simply contains “None”. 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. Extra credit will not be awarded for pure “eye candy,” such as changing the font and color of buttons or adding a border.

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. We will test your solution by running your main program.

Reflection [0.5 point]

Please answer the following questions in a file named reflection.txt in your answers/ directory. Answer briefly, but in enough detail to help you improve your own practice via introspection and to enable the course staff to improve PoS in the future.

  1. In retrospect, what could you have done better to reduce the time you spent solving this assignment?
  2. What could the course staff have done better to improve your learning experience in this assignment?
  3. What do you know now that you wish you had known before beginning the assignment?

Collaboration [0.5 point]

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

The standard academic integrity 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.


General GUI Advice

If you’ve never used Swing, it is well worth your time to do some tutorials, read the example code, and generally get comfortable with GUI programming before diving into the assignment. You can start by studying the examples that came with the GUI lecture.

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 figure out how to use it without directions from you?

As usual, remember to practice good method and class decomposition among other best practices for style. In particular, your GUI constructor and paintComponent will probably be long enough that they should be broken into helper methods. Apply refactoring if you feel that a method or class has become too large.

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

  • hw9/
  • hw9/*.java [your GUI classes]
  • hw9/answers/model-changes.txt [list of changes to HW7. The file may simply contain “None”.]
  • hw9/answers/extra.txt [list of optional features you implemented. The file may simply contain “None”.]
  • hw9/answers/reflection.txt
  • hw9/answers/collaboration.txt

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


None yet. Look at Announcements page.