Hot File

J2ME: Hello World Mobile Application

View: 1011    Dowload: 0   Comment: 0   Post by: naruto  
Author: none   Category: Java mobile   Fields: Computers - Technology

0 point/3 review File has been tested

Download   j2me-hello-world-mobile.rar (7.61 KB)

You need to Sign In to download the file j2me-hello-world-mobile.rar
If you do not have an account then Sign up for free here

Download error   Report copyright violation

Mobile technology is a day-to-day technology that almost everyone has. Some even use this technology more than PC and they are always in need for new features and functionality. These features and functionality are provided using Mobile Applications, so I decided to write a series of articles about building mobile applications.

Introduction

Mobile technology is a day-to-day technology that almost everyone has. Some even use this technology more than PC and they are always in need for new features and functionality. These features and functionality are provided using Mobile Applications, so I decided to write a series of articles about building mobile applications.

Background

J2ME applications are simply Java applications with a limited functionality that are designed to run on mobile devices. The standard Java runtime environment for these devices is provided using Mobile Information Device Profile (MIDP) combined with the Connected Limited Device Configuration (CLDC). MIDP and CLDC simply provide the core application functionality required by mobile applications. To write J2ME applications, you need the Java Platform Micro Edition SDK and an IDE, which can be Netbeans or Eclipse.

Creating MIDlet

All J2ME applications must have a main class which should be derived from a special class called MIDlet. It is like the entry point for the application and manages the life cycle of the application. The MIDlet can be in one of three states: active, paused and destroyed. MIDlet is put into a paused state when the application manager calls pauseApp() method, and when it calls startApp() method the MIDlet is put into the active state. The destroyed state is entered when the MIDlet destroyApp() method is called or when the MIDlet itself calls notifyDestroyed() method.

The MIDlet class is located in the javax.microedition.midlet package, so the first thing to do is to import this package in addition to the javax.microedition.lcdui which contains the J2ME UI components.

import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;

The next step is to create a new class derived from MIDlet class, and to implement the three abstract methods: startApp(), pauseApp() and destroyApp().

public class HelloMIDlet extends MIDlet {
 public HelloMIDlet() {
 }

 protected void startApp() {
 }

 protected void pauseApp() {
 }

 protected void destroyApp(boolean unconditional) {
 }
}

The Display and Displayable 

The J2ME application can run in the background or interact with the user. Interactive applications need access to mobile display by obtaining an instance of Display class. The Display object is used to display the required user interface which should be derived from the Displayable class, in this article an instance of the Form class will be used. The Form is a derived class of the Displayable class, which has a title and you can add contents to it using other UI components.

So the next step is to define two data members of the Display and Form classes.

 
public class HelloMIDlet extends MIDlet {
 private Display display;
 private Form helloFrm;
 ...
} 

In the constructor of MIDlet class, creates an instance of Form class by calling the constructor and passing the form title to it.

public HelloMIDlet() {
 helloFrm = new Form("Hello World");
} 

Display The Form

The next step is to obtain an instance of the Display class and display the form. To get an instance of the Display class, you call the Display class static method getDisplay() and passing a reference to the MIDlet object to it. Next, use the Display object setCurrent() method to display the Form.

protected void startApp() {
 display = Display.getDisplay(this);
 display.setCurrent(helloFrm);
} 

Conclusion

This article describes how to create a J2ME Hello World mobile application. The first step which is required for all J2ME applications is to create the MIDlet class, which is the main class in your application. Then you can use an instance of the Form class as the main UI in the application, which should be displayed using an object of the Display class.

Following is the complete application code:

import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;

public class HelloMIDlet extends MIDlet {
 private Display display;
 private Form helloFrm;

 public HelloMIDlet() {
 helloFrm = new Form("Hello World");
 }

 protected void startApp() {
 display = Display.getDisplay(this);
 display.setCurrent(helloFrm);
 }

 protected void pauseApp() {
 }

 protected void destroyApp(boolean unconditional) {
 }
}

J2ME: Hello World Mobile Application

J2ME: Hello World Mobile Application Posted on 21-03-2014  Mobile technology is a day-to-day technology that almost everyone has. Some even use this technology more than PC and they are always in need for new features and functionality. These features and functionality are provided using Mobile Applications, so I decided to write a series of articles about building mobile applications. 5/10 1011

Comment:

To comment you must be logged in members.

Files with category

 
Newsletter Email

File suggestion for you

File top downloads

logo codetitle
Codetitle.com - library source code to share, download the file to the community
Copyright © 2015. All rights reserved. codetitle.com Develope by Vinagon .Ltd