Netbeans mobility pack 5.5 Quick Start Guide

Source: Internet
Author: User
Tags netbeans
This document introduces how to use netbeans ide 5.5 to create Java? Platform Micro Edition (Java? Me platform) Basic knowledge of mobile information device profile (MIDP) applications. This document aims to help you get started quickly. The following documents provide detailed information on the use of Java me support in the netbeans development environment:

Import existing Java me MIDP/cldc source code to netbeans ide
The following tutorial briefly describes some basic steps for using the new project system. We will introduce you to two methods to create a Java me MIDP project named "myhello", which will display the text "Hello World" in the device simulator ".

Requirements
You must install netbeans ide 5.5 and netbeans mobility pack 5.5 before developing Java me MIDP/cldc. For instructions on downloading and installing the complete environment, see the mobility pack documentation and support page.

Use the visual mobile designer to create a MIDP Application
Netbeans ide provides a wizard to quickly create a MIDP project. When creating a project, you can choose to develop applications in the visual mobile designer (vmd) or source code editor.

When using the visual mobile designer, you can graphically plan the application stream and design the screen used by the application. The designer automatically creates code for the application.

Create a MIDP/cldc Application
Select "file"> "new project" (CTRL-shift-N ). Select "mobile" under "category", select "mobile application" under "project", and click "Next ".
Enter myhello in the "Project name" field. Change the project location to any directory on the system. From now on, the directory is called $ projecthome.
Select the "set as main project" and "create Hello MIDlet" check boxes (by default, both check boxes are selected ). Click "Next ".
Use the j2e-wireless Toolkit as the target platform.
Click Finish ". At this time, IDE creates the $ projecthome/myhello project folder. The project folder contains all source code and project metadata, such as the project ant script.
The application itself is displayed in the streaming design window of the visual mobile designer.

Edit Java source code
Now, let's edit the text displayed by the MIDlet.

Click screen design ".
This opens the screen designer window and displays the helloform [Form] screen, which is the only available screen in the application.
Double-click "Hello world! "Text and type some new text.
Compile and run the project
Select "run"> "run main project" (F6) from the "run" menu ). Double-click the "output" window to maximize all output content. Note that the hellomidlet. Java file is built before execution. In this way, a device simulator is opened to display the execution MIDlet result. The default device simulator is defacolorcolorphone.
In the device simulator window, click the button under the "Start" command. The device simulator starts the MIDlet and displays the text entered in the source code.
Click the button below "exit" to close the MIDlet, and then click the button in the upper-right corner of the device to close the simulator window.
Use the source code editor to create a MIDP Application
When using the source code editor, you can manually create code for the MIDlet. By creating code in the source code editor, you can edit the code more flexibly and insert Preprocessing Program code blocks.

Now, we will use the "new project" and "new file" Wizard to create the same application and use the source code editor to complete the code.

Create a new Java me MIDP Project
Select "file"> "new project" (CTRL-shift-N ). Select "mobile" under "category", select "mobile application" under "project", and click "Next ".
Enter myhellomidlet in the "Project name" field. Change the project location to any directory on the system. From now on, the directory is called $ projecthome.
Select the "set as main project" check box, and deselect the "Create Hello MIDlet" check box. Click "Next ".
Use the j2e-wireless Toolkit as the target platform.
Click Finish ". At this time, IDE creates the $ projecthome/myhellomidlet project folder. The project folder contains all source code and project metadata, such as the project ant script.
In the "project" window, right-click the myhellomidlet node and choose "New"> "file/folder ".
Select "MIDP" under "category", select "MIDlet" under "file type", and click "Next ".
Enter hellomidlet as the MIDlet name. Click Finish ". The hellomidlet. Java file will be created.
Double-click the hellomidlet. Java file to display the source code in the editor.
In the source code editor, click
Public class hellomidlet extends MIDlet

Change
Public class hellomidlet
Extends MIDlet implements javax. microedition. lcdui. commandlistener
{
Add the following text to the front of the Startapp () method:
Public hellomidlet (){
} Private void initialize () {javax. microedition. lcdui. display. getdisplay (this). setcurrent (get_hellotextbox ());}
Public void commandaction (javax. microedition. lcdui. Command command, javax. microedition. lcdui. displayable
Displayable) {If (displayable = hellotextbox) {If (command = exitcommand) {javax. microedition. lcdui. display. getdisplay (this ). setcurrent (null); destroyapp (true); policydestroyed ();}}
}
Private javax. microedition. lcdui. textbox get_hellotextbox () {If (hellotextbox = NULL) {hellotextbox = new javax. microedition. lcdui. textbox (null, "test string", 120, 0x0); hellotextbox. addcommand (get_exitcommand (); hellotextbox. setcommandlistener (this);} return hellotextbox ;}
Private javax. microedition. lcdui. command get_exitcommand () {If (exitcommand = NULL) {exitcommand = new javax. microedition. lcdui. command ("exit", javax. microedition. lcdui. command. exit,
1);} return exitcommand ;}
Javax. microedition. lcdui. textbox hellotextbox; javax. microedition. lcdui. Command exitcommand;
Add one initialize (); line to the Startapp () method, as shown below: Public void Startapp (){
Initialize ();
}
Edit Java source code
Now, we will add some text for the display by the MIDlet.

In the get_hellotextbox () method, replace the "test string" code with the selected text. For example, "Hello World ".
Compile and run the project
Select "run"> "run main project" (F6) from the "run" menu ). Double-click the "output" window to maximize all output content. Note that the hellomidlet. Java file is built before execution. In this way, a device simulator is opened to display the execution MIDlet result. The default device simulator is defacolorcolorphone.
In the device simulator window, click the button under the "Start" command. The device simulator starts the MIDlet and displays the text entered in the source code.
Click the button below "exit" to close the MIDlet, and then click the button in the upper-right corner of the device to close the simulator window.
Change the simulator Platform
The simulator platform is provided by mobile phone manufacturers. Therefore, developers can simulate specific mobile device behavior when coding, debugging, and testing applications. Netbeans mobility pack contains the j2rwireless toolkit and supports many other software development kits (sdks). You can use the vendor site (such as Nokia, Sony Ericsson, or Motorola) download these toolkit.

Change the default simulator device
Right-click the "myhello" project node and select "properties ". In the "properties" dialog box, select the "Platform" node. You can change the default configuration of the device.
Click the device drop-down list and select qwertydevice ". Click OK ".
Run the application again. The application runs in the qwertydevice simulator.
Add a new simulator Platform
Select Tools> JAVA Platform manager from the main toolbar ".
In the "Java platform manager" dialog box, click "add platform.
On the "select platform type" Page, select "Java Micro Edition platform Simulator ". Click "Next ".
On the platform page, IDE searches for all available Java me platforms and lists them in the window. IDE verifies platforms that comply with the unified emulator interface (UEI) standards and displays a check mark in the check boxes next to these platform names. Platforms that do not comply with UEI or that cannot be installed for other reasons will be listed in red. The wizard can also identify the platform that has been installed.

Note: To install a platform that does not comply with UEI, click "previous" and select "Custom Java Micro Edition platform Simulator ".
On the platform page, select the check box next to any platform simulator to be installed, and click Finish ". Click Close ".
The system installs one or more selected platforms.
Select "file"> "'myhello' property ".
Select the "Platform" node, and then select the name of the new simulator from the "simulator platform" drop-down menu (for example, j2_wireless toolkit 2.2 ). Click OK ".

 

 

 

 

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.