Introduction
In the previous articles, I've mentioned under most cases you have to seek help for some game map editors to accelerate your game development. The case is the same for the previous PushBox game I've introduced. In the PushBox game, I, with the help of a 2D game map editor, created the map arrays defined in the file MapList.Java (as well as MapList.cs). In this article, we are going to create our own game map editor using Java language. For simplicity, we are only to construct a 2D map editor, which will output a two-dimensional array as the result.
NOTEThe sample development environments in this article involve:
1. Windows 7;
2. .NET 4.0;
3. JDK (jdk-6u24-windows-i586.exe);
4. Eclipse 3.6 (Helios Service Release 2);
5. Google Web Toolkit (optional).
Set up the Project Sketch
Start up the Eclipse IDE, click the menu item 'File|New|Project...' to open the 'New Project' dialog, and select the 'SWT/JFace Java Project' template, as shown in Figure 1.
Figure 1: Create a Java project with SWT/JFace support

From the next wizard page input the project named MapEditor and click OK to exit the wizard.
Click the 'src' folder, and then click item 'Create new visual classes' from the toolbar. From the sub menu, select the item 'Swing | Application Window' to create a main Swing application, named MapEditor, as shown in Figure 2 below.
Figure 2: Create a main Swing application

Next, click the item 'Create new visual classes' from the toolbar and select the item 'Swing | JPanel' to create a custom JPanel component named SplitPanel. And then, from the toolbar select the item 'Swing | JFrame' to create two custom JFrame components named MapEditorMinor and ResultFrame, respectively.
NOTEIn this sample application, I've utilized the traditional framework Swing. In fact, you can also select the popular SWT or latest GWT frameworks to create the sample code.
Finally, let's look at the final Package Explorer corresponding to the sample project, as shown in Figure 3 below.
Figure 3: The simple folder architecture of the sample project

Next, let's further look at the main running-time snapshots in the simple map editor. Figure 4 illustrates the main interface of the map editor.
Figure 4: The main interface of the map editor

And then from the menu click the menu item 'File | Open' to open an image file, as shown in Figure 5 below.
Figure 5: Using the map editor to open a sample game image

Next, click the button 'OK' at the bottom right to open another window, as shown in Figure 6.
Figure 6: The true game map editor (the bottom provides the target image blocks and the top provides the final game scene with selected gadgets at appropriate positions)

Next, click the menu item File | Generate and you will see the snapshot in Figure 7.
Figure 7: Generate the final map data using the game map editor

Well, with the main screenshots in mind, let's next introduce how to construct the map editor tool in this article.
Create the Main Interface - the MapEditor Class
With the help of visual Swing UI designer, creating most of the user interface gadgets is easy enough. Figure 8 indicates the design-time screenshot of the MapEditor class.
Figure 8: The design-time screenshot of the MapEditor class

There are two parts (the menu and the placeholder to hold the image) in Figure 8 that will be dynamically added, so you will not see them. Since our main interests do not dwell upon the Java gadgets design, we will mainly pay attention to the most meaningful parts.
First, we've defined two important variables of types JScrollPane and SplitPanel respectively, by which we will show the image to be imported and facilitate the screen scroll.
In the above code, sp is a custom JPanel defined in another file SplitPanel.Java to be discussed later on. The JScrollPane instance jsp is used to render the image.
Next, we derive the MapEditor class from two interfacers, ActionListener and ChangeListener, with which we will subscribe to our interested action listeners. Since these action listeners can serve any gadgets in the class, this helps to simplify the application design.
The rather important method should be actionPerformed. First, when the user clicks the menu item 'Open' an open file dialog is shown. Next, we create an instance of SplitPanel and put it into an instance of a JScrollPane. At last, by invoking the method of getContentPane() of JFrame we show the scroll pane and accordingly show the contained image.
When the user clicks the button 'OK' at the bottom right, this form (MapEditor, a JFrame) will be closed and another window MapEditorMinor is created and opened, with the related parameters passed in.
Next, let's look into other related stuffs involved in the above story.
Create the Custom SplitPanel Class
The SplitPanel class is a custom JPanel with which to display the big image that generally contains a couple of small pictures. First of all, let's take a look at the related code.