First application in j2me “Hello world” project

Hi all, ;;)
I Hope you completed first step well. You need to go through all topics serially. For todays project you need all the necessary things that i suggested you in first topic. (introduction to j2me)
Well, Todays class is quite intresting and a starting. Today you will make your first “Hello world” application.
Ok lets start.
>” /> Open your Netbeans software.<br />
<img title=  Hurraahh!! Give me a party? :d
Now you’re done but may be you are thinking what are these coding? :-?? Right?
First do it i will explain each and every line in this same topic.
Enjoy! I will be happy if you print hello world screen with your name and upload somewhere and pm me link so i can check it how you doing :d

This was the code for better hello world example.

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

public class HelloWorld extends MIDlet implements CommandListener{
private Form form;
private Display display;

public HelloWorld(){

}

public void startApp(){

form = new Form(“Hello world”);
String msg = “Hello world”;
form.append(msg);
display = Display.getDisplay(this);
display.setCurrent(form);
}

public void pauseApp(){}

public void destroyApp(boolean unconditional){
notifyDestroyed();
}
public void commandAction(Command cmd, Displayable disp) {

}
}

Now i will try to make you easier understanding about these codes.

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

You need to import these API’s in every midlet.
Lcdui Contains the Java ME-specific classes used for the graphical user interface. So if you gonna have some gui in your application then you need to import it.
Midlet Contains the base classes for Java ME applications. You need to import it in main class(esp)

public class HelloWorld extends MIDlet implements CommandListener{

This main class extends Midlet. And about Commandlistener You can remove it but these Commanlistener means: Later we will make menus in the application then we need to use it to listen user commands.

private Form form;

The Displayable. This component is displayed on the screen.

private Display display;

The Display. This object manages all Displayable components.

public HelloWorld(){
}

This is a constructor needed to defined in every midlet. You can pass any values here. Later you will understand more.

public void startApp(){

What ever function and print out you do within this startApp that will be displayed on the starting of application. So we are going to print hello world.

form = new Form(“Hello world”);

Create a Displayable widget. This is form only.

String msg = “Hello world”;

Add a string to the form

form.append(msg);

It makes the string to be printed within the form.

display = Display.getDisplay(this);

This app simply displays the single form created above.

display.setCurrent(form);}

Sets current screen to the form. ater we will make 2 or more forms then menus and we will use driven programing then you will know exact work of setcurrent.

public void pauseApp(){}

public void destroyApp(boolean unconditional){
notifyDestroyed();
}
public void commandAction(Command cmd, Displayable disp) {

}
}

This are the abstract methods which needs to implemented in every midlet. Pauseapp works when we need to pause the application. Destroy app works when we need to exit. Comand action works in driven programming. When we will make menu comand and we will explain user commands action here. ;;)
It’s easy. Try doing something new with these coding. You will gain more knowledge ;)
I’m Waiting for questions.
Best of luck!

Author: pradeep

Share This Post On

Submit a Comment