Java代写,java作业代写:100%原创代码
当前位置:以往案例 > >案例计算机JAVA案例关于地图编辑器
2018-10-06




1 Overview
In this project, you will implement a complete graphical Map editor, in a class called MapEditor, that permits editing of maps and simple trip planning. The map that you display will be stored in the MapImpl class you wrote for project 2. Your Map editor program should be able to read a map from a file, or write one to a file, using the MapReaderWriter class you built previously. You will also be able to plan trips via the methods in your MapImpl class.


2 Specification
Exercise 1 Building the GUI

Your GUI will have a single large panel to display a representation of the map you are editing. There will be a menu-bar with two items to allow a user to control the program:

A [File] menu that contains the options: [Open…], [Save as…], [Append…], and [Quit].

– The [Open…] item pops up a file dialogue (JFileChooser) and allows the user to choose a map file to read in and display. Any existing map on the display is discarded.

– The [Save as…] item pops up a file dialogue (JFileChooser) and allows the user to choose a file, or enter a file name, into which a repre- sentation of the map currently presented on the screen will be written.

– The [Append…] item pops up a file dialogue (JFileChooser) and allows the user to choose a map file to read in and append to the existing diagram. Note that the default file-extension for all map files is “.map”.

– The [Quit] item allows the user to quit the program. If the user has made changes to the map that have not been saved to a file, the program should warn the user and offer the choice of proceeding or cancelling.

An [Edit] menu that contains the options: [New place], [New road], [Set start], [Unset start], [Set end], [Unset end], and [Delete]. These op- tion are described in more details below.

You should also add a keyboard shortcut for each file-menu item (see JMenuItem.setAccelerator()). These are:

• [File] → [Open]: Control-O

• [File] → [Append]: Control-A




• [File] → [Save as]: Control-S

• [File] → [Quit]: Control-Q

Attach a listener to the [Quit] item that will cause your program to quit. For the moment, attach listeners to the other menu items that simply print out an appropriate message (such as “Open selected”, when the open menu item is selected). Please, make sure that your editor can be resized!


Exercise 2 Verify the basics

You should build all of the above parts in a class named MapEditor and then verify that each part is working before proceeding. Your MapEditor class should contain a main() method so that your program can be executed. Verify that all  the menu items function correctly and print out the expected messages. Verify that [Quit] causes the program to quit. Do not proceed until you have verified all is well!


Exercise 3 Read and write files

Extend your program so that the [Open], [Append], and [Save as] menu items correctly open and read in, append, and save map files. You should use the MapImpl and MapReaderWriter classes you wrote for project 2 to do this job. Open a file and verify that you can successfully save it again. Read in a file, append another to it, and write out the result. Check that the result is correct.

If an exception is thrown by the MapReaderWriter code, your program should pop up a dialogue box (JDialog) that displays the error message, and then allow the user to press an [Ok] button to dismiss it. Read in a file that has errors and check that the error dialogue pops up and can be dismissed. After an error, verify that you can still open another file correctly. Once again, test thoroughly.


Exercise 4 Build the map panel

Create a new class, named MapPanel, that extends JPanel and implements MapListener, and add it to the main JFrame of your MapEditor. Make sure that the layout man-

ager for this panel is set to null, or you will experience a lot of strange behaviour later on. MapPanel will need to implement the three methods of the MapListener interface. For the moment, each of the three methods should simply print out a message that says something like “placesChanged” when the method is called.


Exercise 5 Test the MapListener

Similarly to exercise 3, test your program

在线提交订单