Develop J2ME programs using Eclipseme

xiaoxiao2021-03-06  51

This article describes the full process of a simple mobile app to develop J2ME plugins in an Eclipse development environment. Before reading this article, you need to know the tools and techniques used.

I. Installation and configuration Preparation requires Eclipse 3.0M9, J2ME Wireless Toolkit 2.1 and Eclipseme, Eclipse is an open source IDE development environment funded by IBM, and Eclipse is receiving 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.

File download address:

L Eclipes (3.0): http://www.eclipse.org/downloads/index.php

l Eclipesme (0.46): http://eclipseme.sourceforge.net/

l J2ME Wireless Toolkit (2.2beta): http://java.sun.com/products/j2mewtoolkit/download-2_2.html

l Proguard (2.1): http://proguard.sourceforge.net

Second, 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

Third, file package

l Package: Right click on the project -> J2me-> CREATE PACKAGE Matching the package in the deployed directory

l Desert a package: You need to configure ProGuard: Window-> Perferences-> J2ME-> Platform Components-> OBFUSCATION Select ProGuard paths Advising USE Specified Arguments: "- dontusemixedcaseclassnames" Otherwise it is possible to create case under Windows. After configuration, right-click -> J2me-> Create Obfuscated Package

When you use the EclipseMe to automatically package function, it is found that it is best to create a source folder, and put all files in this folder, and the completed compilation output of the other class is also a proprietary directory, otherwise the package is packaged. J2meexam.jar often monks.

转载请注明原文地址:https://www.9cbs.com/read-114351.html

New Post(0)