Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Java code please. Please help Objective 1: GUI Setup As with the rhymes project, we will begin by setting up the layout for the project.
Java code please. Please help
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 1. Create a new project in Eclipse 2. Create a new package in the src folder named "maps 3. In the maps package, create a new package named "cities" 4. 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 5. 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) i. 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) ii. 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) 6. 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 ora 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.pack0; 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 1. Create a new project in Eclipse 2. Create a new package in the src folder named "maps 3. In the maps package, create a new package named "cities" 4. 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 5. 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) i. 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) ii. 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) 6. 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 ora 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.pack0Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started