Hello World for the development of j2's program in eclipse

Source: Internet
Author: User

Previous articles Article The installation and configuration of eclipse and its working environment have been introduced, and various preparations have been completed. Therefore, this article describes how to use the previously configured eclipse

The development environment is used to create a j2e-based project and start a real journey of j2-based development. Because this is the first created Program According to the practice of program development, it is naturally not "Hello World. Although helloworld has simple functions, it is very small and dirty. Through the development of this small program, it can completely familiarize readers with the general process of the development of the program.

Create a J2EE Project

Similar to the development of applications in other languages, you must first create a project and all subsequent coding, debugging, and running processes for the development of a j2-based program are carried out in this project. After eclipse is started, click "new" under the "file" menu to bring up the "project" menu. The new project wizard dialog box is displayed as follows:

First, you need to specify the project to be created, expand the j2_project, select the j2_midlet suite sub-item, and proceed to the next step. The Wizard Page (as shown below) is used to set the project name and Project Storage path. Generally, the default path is used. The project name is the classic "helloworld. After completing the settings, proceed to the next step.

This wizard page needs to specify the MIDP version supported by the application. If compatibility is considered, you can select the j2e-wireless toolkit 2.1 MIDP 1.0 platform. You can also choose MIDP 2.0, but there are still a few mobile phones that support MIDP 2.0. Click Next to define the Java build settings. Generally, you can use the default value. After you click "finish", eclipseme automatically sets the project editing and running environment. You can click the helloworld. Jad item in the navigator view. In the edit view on the right, you can view the project structure generated by eclipseme:

Create a J2EE Application

I just created a MIDlet suite, also known as the MIDlet

Application Suite, which can contain one or more MIDlet, is only performed in the unit of MIDlet suite at the time of release. All the substantive work is done in the MIDlet. Therefore, you need to add the MIDlet to the project. Right-click the navigator, select "new" and "other" from the pop-up menu to start the displayed dialog box, select the j2_midlet sub-item under j2_m2. then go to the next step:

Here, you need to specify the package (or the default value) and name. After you click Finish, eclipseme will automatically generate the frameworkCode. You can add the necessary functional code (Shadow) to it to display the "Hello World" character.

Package demo;
Import javax. microedition. MIDlet. MIDlet;
Import javax. microedition. MIDlet. midletstatechangeexception;
Public class helloworldmidlet extends MIDlet {
Private textbox;
Public helloworldmidlet (){
Super ();
Textbox = new Textbox ("test program", "Hello world! ", 20, 0 );
}
Protected void Startapp () throws midletstatechangeexception {
Display. getdisplay (this). setcurrent (textbox );
}
Protected void pauseapp ()
Protected void destroyapp (Boolean arg0) throws midletstatechangeexception
}

After adding the code for the above function, an error icon is displayed. This is because the corresponding package is not imported. This is similar to the lack of referenced header files in C ++. Unlike C ++, if you need to manually Add a reference to an object, you can click"Source codeUnder the menu "organization import" menu, eclipseme automatically adds the required packages to the project:

Import javax. microedition. lcdui. display;
Import javax. microedition. lcdui. textbox;

Run helloworld

The Code has been compiled. Click "run"> "Run..." under the "run" menu ...... "Menu items to bring up the configuration interface as shown in. In the left-side configuration window, right-click "wireless toolkit emulator" and choose "New" from the shortcut menu.

The following running configuration property page is displayed. The default settings are optional. You can also specify the default device on the "emulation" tab. You can use the defaultclolorphone item to simulate the running effect on the cell phone. Currently, mobile phones that support Java are generally not very low in configuration, and most of them are color screen configurations. Therefore, the "defaultclolorphone" option should be quite popular. Of course, you can also set "defaultgrayphone" and other projects to simulate the running effect on a monochrome or other mobile phone configurations.

Finally, click the "run" button to execute the first j2_c program we just created. A cell phone pattern window shown below is displayed. This is the mobile phone simulator. It can simulate all the buttons on the mobile phone, with the same functions as the real machine. Observe its screen and display the "Hello World" text displayed by the newly compiled j2_program. Although only a few characters are displayed, it indicates that we have already begun to enter the world of j2s. In the next article, we will describe the real-machine publishing process of the j2's program to complete the production and release of a real mobile app.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.