This guide will walk you through building the required map-animation application using Java Swing and JMapViewer.
- JDK 8 or higher (JDK 11+ recommended)
- JMapViewer JAR included in the project lib folder
- TripPoint.java and StopDetector classes prepared
- IconMarker.java and raccoon image resource if using a custom marker
- Map display centered on trip area (20 pts)
- JComboBox for animation speed: 15, 30, 60, 90 seconds (10 pts)
- JCheckBox labeled "Include Stops" (10 pts)
- JButton to start/reset animation (10 pts)
- Current position shown with raccoon icon (10 pts)
- Trail path drawn behind raccoon (10 pts)
- Animation timing correctly matches selected duration (30 pts)
Before launching the GUI, load trip data and detect stops.
- Load CSV data:
List<TripPoint> allPoints = TripPoint.loadFromFile("triplog.csv");
- Detect moving points:
List<TripPoint> movingPoints = StopDetector.h1(allPoints);
Store allPoints and movingPoints for later use in animation.
Start from the provided Project5Template.java. Fill in the TODOs.
-
Top Panel:
- Add JComboBox animationCombo with values {"15", "30", "60", "90"}.
- Add JCheckBox includeStopsCheckbox, default unchecked.
- Add JButton playButton labeled "Play".
-
Map Panel:
- Instantiate JMapViewer mapViewer.
- Enable wrap-around scrolling.
- Center the map using coordinates of your trip.
Attach an ActionListener to the Play button.
playButton.addActionListener(e -> {
mapViewer.removeAllMapMarkers();
mapViewer.removeAllMapPolygons();
List<TripPoint> data = includeStopsCheckbox.isSelected() ? allPoints : movingPoints;
int seconds = Integer.parseInt((String) animationCombo.getSelectedItem());
animateTrip(data, seconds);
});Use a Swing Timer for animation.
int delay = (seconds * 1000) / points.size();
Timer timer = new Timer(delay, null);
final int[] index = {0};
timer.addActionListener(evt -> {
if (index[0] >= points.size()) {
((Timer) evt.getSource()).stop();
return;
}
TripPoint p = points.get(index[0]);
// Update raccoon marker position
// Draw line from previous to current point
index[0]++;
mapViewer.repaint();
});
timer.start();- Raccoon marker should replace or move.
- Line should connect previous and current TripPoint.
- Keep model and view code separated.
- Use resources properly (raccoon.png inside resources folder).
- Make sure animation timing matches total seconds accurately.
- Clear old markers and lines before starting a new animation.
- Make sure the trip centers properly on load or after play.
Follow these steps to properly add jmapviewer-2.24.jar to your Eclipse project.
- In your project root (e.g.,
cs2334sp23project5), create a new folder calledlibif it doesn’t already exist. - Place your
jmapviewer-2.24.jarfile into thislibfolder.
- In Eclipse, right-click the project name in the Project Explorer.

- Navigate to
Build Path → Configure Build Path…

- Go to the
Libraries → Classpathtab and clickAdd JARs…

- Navigate to the
libfolder inside your project and selectjmapviewer-2.24.jar
- Click
OK, then clickApply and Close
-
You should now see
jmapviewer-2.24.jarlisted underClasspathin the Build Path window -
You should also see it listed under
Referenced Librariesin the Project Explorer
If your project has a file named module-info.java, delete it. This file is not required and can interfere with importing external libraries like JMapViewer.