[转] Teach you how to develop J2ME programs using Eclipseme (3)

xiaoxiao2021-03-06  21

Author: Wan Hui

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

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

New Post(0)