This article describes how to develop J2ME applications using the EclipseMe plugin in Eclipse IDE. This article introduces the EclipseMe plug-in and its installation configuration steps, and introduces how to build a basic J2ME application through a simple example.
I. Installing and Configuration Preparation You need to install Eclipse 3.0m9, J2ME Wireless Toolkit 2.1 and Eclipseme, Eclipse is an open source IDE development environment funded by IBM, and Eclipse is being followed by more and more developers. J2ME Wireless Toolkit 2.1 provides libraries needed to run J2ME applications and simulators. The EclipseMe plugin allows developers to easily develop J2ME applications in the Eclipse environment.
1 Install link on where to download the following software, see the reference part:
1. Download Eclipse V3.0M9 from the Eclipse's Web site. You can install it by extracting it to any selected directory (this directory is called Eclipse_home here).
2. Download J2ME Wireless Toolkit 2.1 on Sun's Web Sites. You can install it into any selected directory (this directory is called wtk_home herein).
3. Download the EclipseMe plugin V 0.4.5 from the SourceForge. You can install it by extracting it into the Eclipse_home / eclipse / plugins directory.
4. Download J2SE SDK from Sun's Web Sites. You can install it to any selected directory (this directory is called java_home herein). The version of J2se SDK in this article is V1.4.2.
2 Configure the Eclipseme plugin To configure the EclipseMe plugin, perform the following steps:
Start Eclipse.
2. Configure the EclipseMe plugin. To implement this feature, click the Window menu, then select the "Preferences" menu item, then select "J2ME" in the pop-up menu. Then perform the following steps:
Click "Platform Components", see Figure 1. Right-click "Wireless Toolkits", select "Add Wireless Toolkit", will pop up (see Figure 2), "Wireless Toolkit Directory is set to WTK_HOME corresponding to the installation directory.
Figure 1 Eclipseme plugin configuration interface
3. The interface as shown in Figure 3 should occur after the installation is complete.
Figure 2 Add Wireless Toolkit
Figure 3 Configure the Eclipseme plugin - the final result
Second, develop J2ME Apps In this section, we will introduce the basic steps to build J2ME applications using the Eclipseme plugin. First, you will create a J2ME project. Then you can start your J2ME development trip.
1 Create a J2ME project To create a J2ME project, return to the File menu, select "New" item and select "Project" in the submenu. Then perform the following steps:
(1.) Enter the "J2ME" option and select "J2ME MIDlet Suite" and click "Next" (see Figure 4).
(2.) Fill in the project name and click "Next" (see Figure 5). (3.) Select a possible platform definition. You can choose "J2ME Wireless Toolkit 2.1 Midp1.0 Platform" or "J2ME Wireless Toolkit 2.1 Midp1.0 Platform", which is the former. (See Figure 6).
(4.) Click "Next", the J2ME project appears, where we all use the default setting (see Figure 7).
(5.) Click Finish to complete the project creation.
The result of the final creation J2ME project is shown in Figure 8.
Figure 4. Creating a J2ME item - Step 1
Figure 5. Creating a J2ME project - Step 2
Figure 6. Creating a J2ME project - Step 3
Figure 7. Creating a J2ME item - Step 4
Figure 8. Creating a J2ME project - the final result
2 Develop J2ME Project To create a J2ME application, return to the File menu, select the "New" item and select "Other" in the submenu. Then perform the following steps:
(1). Go to the "J2ME" option and select "J2ME MIDlet" and click "Next" (see Figure 9).
(2). Fill in the application name, other settings use the default settings, and click "Finish" (see Figure 10) to complete the application.
Figure 9. Creating a J2ME application - Step 1
Figure 10 Create a J2ME application - Step 2
The system will automatically generate the HelloWorld.java program and a automatically generated code, and the final program code is shown in Listing 1.
Listing 1. HelloWorld.java
/ **
* HelloWorld.java
*
* @Author Wanhui
* /
Import javax.microedition.lcdui.display;
Import javax.microedition.lcdui.textbox;
Import javax.microedition.midlet.mIdlet;
Public class helloworld extends midlet {
Private textbox textbox;
/ **
* Constructor of the HelloWorld Class
* /
Public helloworld () {
TextBox = New TextBox ("", "Hello World!", 20, 0);
}
/ *
* The Startapp Method Is Used for Starting OR Restarting A MIDLET.
*
* @see javax.microedition.midlet.mIdlet # startapp ()
* /
Public void startapp () {
Display.getdisplay (this) .SetCurrent (TextBox);
}
/ *
* The PauseApp Method Is Called by The System To ask a midlet to "pause"
*
* @see javax.microedition.midlet.midlet # PauseApp () * /
Public void pauseApp () {
}
/ *
* The destroyapp method is caled by the system when the midlet is about to
* Be Destroyed
*
* @see javax.microedition.midlet.midlet # destroyApp (boolean)
* /
Public void destroyApp (boolean unconditional) {
}
}
3 Run a J2ME application To run a J2ME application, select an application, this article is HelloWorld.java, then return to the "Run" menu, select the "Run As" item, and select "1 Emulated J2ME MIDlet ". Eclipse then starts the simulator in J2ME Wireless Toolkit 2.1 to get the results of the results shown in Figure 11.
Figure 11 J2ME application operation results
Conclusion In this article, we introduced the J2ME program using the EclipseMe plugin in the Eclipse IDE development environment. You have learned how to create a simple J2ME application in the Eclipse environment.
Reference
Download the source code in this article. Download J2ME Wireless Toolkit 2.1 from Sun's Web Sites. Download Eclipse V3.0M9 from the Eclipse's Web site. Download Eclipse Me from SourceForge. Read "J2ME Documentation" on Sun's Web site. In detail in the Java? 2 Platform, Micro Edition, SECOND Edition, gives a guide to build J2ME applications (Addison Wesley, 2003). The Struts framework is detailed in James White and David Hemphill, James White and David Hemphill. MIDP (Addison Wesley, 2002) in MIDP 2.0 Style Guide for the Java? 2 Platform, Micro Edition.