Question: City Data Download: cities.csv This project includes GeoLite data created by MaxMind, available from http://www.maxmind.com In this project we will be taking advantage of city

City Data

Download: cities.csv This project includes GeoLite data created by MaxMind, available from http://www.maxmind.com

In this project we will be taking advantage of city location and population data from MaxMind which provides location and population data for thousands of cities from hundreds of countries. The cities.csv file contains a subset of the data set that has been modified to be suitable for this project (Contains only cities with population data; accent names removed; header line removed) in the csv format "Country,City,Region,Population,Latitude,Longitude". This is the exact file that will used while testing your project in AutoLab. Please visit the source website for more information about this data as well as a download of the unmodified data set.

Map Tile API

Documentation: http://wiki.openstreetmap.org/wiki/Slippy_map_tilenames API root: "http://a.tile.openstreetmap.org/" Sample usage: http://a.tile.openstreetmap.org/6/17/23.png

To get map images in our program we will use the freely available open street map tile server. This API serves partial images of the world map called tiles. A specific tile is requested by specifying the x and y locations as well as the zoom level of the desired tile where x and y are computed using a Mercator projection. Review the documentation for more details about requesting tiles and computing the projection. Note that the site provides example code that you cannot use since you did not write it and it's not provided by the course. You can however use these examples as a reference and implement them in your own way with your own code.

Objective 1: GUI Setup

As with the rhymes project, we will begin by setting up the layout for the project. In fact, the structure of this project is similar to the rhymes project throughout the 5 objectives.

Tasks

Create a new project in Eclipse

Create a new package in the src folder named "maps"

In the maps package, create a new package named "cities"

In the cities package, create a new class named "Cities" with a public constructor that takes a String as a parameter. The body of the constructor can be empty for now. We will add methods and instance variables to this class in later objectives

In the maps package, create a new class named "MapGUI" with a public constructor that takes an instance of the Cities class as a parameter. In this class write the following two methods that return JPanels (Hint: Many of the components on this gui will need to be accessed in other methods later. Initializing them in the constructor and storing them in instance variables now can save time later)

A public method named "getSearchPanel" that takes no parameters and returns a JPanel. This JPanel will contain a JTextField that will be a search bar, a JComboBox of type City that will contain the current search results, and a JButton that will set the map to the currently selected City. For now, add these three without any functionality. (In the example image this is the NORTH panel on the JFrame)

A public method named "getMapPanel" that takes no parameters and returns a JPanel. This method will contain 9 JLabels in a 3x3 grid where each JLabel will eventually contain a map tile image. For now, do not add anything to these JLabels. To get the JLabels to line be organized properly we will use a different layout manager for this panel. We will use the GridLayout with 3 rows and 3 columns which can be achieved with the code "panel.setLayout(new GridLayout(3, 3));" assuming your panel is stored in a variable named panel. With this layout components will be added to the panel in a 3x3 grid in row major order starting with the upper left (same order as reading a page). For example, the first 3 elements added to this panel will be placed in the first row, then the next 3 elements will be added to the second row. (In the example images this is the CENTER panel on the JFrame)

In the maps package, create a new class named "Main" and write a main method in this class. This class will be the only one with a main method or a JFrame. Do not add a JFrame anywhere else in your project. In this class you can test and play your game by setting up a JFrame in the same way we've been using in the class and adding the two GUI panels to the locations given above. You will need to create new Cities and MapGUI instances to setup this JFrame. The JFrame in the image was sized by calling frame.pack();

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!