Monday, August 10, 2009

How to Run J2ME application In NetBeans?

First of all u need to Install
  • Java in your Computer. Download JDK from http://java.sun.com/javase/downloads/index.jsp
  • Netbeans Mobility Pack or Latest Version Form http://www.netbeans.org/downloads/

Once You Installed the Application Mean Open Neatbeans

Step 1:
  1. Choose File > New Project (Ctrl-Shift-N). Under Categories, select Mobility. Under Projects, select MIDP Application and click Next.
  2. Enter Project Name field . Choose the Diretory you want to save the project.
  3. Check the Set as Main Project checkbox and remove the check from the Create Hello MIDlet checkbox. Click Next.
  4. Select the Sun Java Wireless Toolkit 2.52 for CLDC as the Emulator Platform and use the remaining defaults. Click Finish.
  5. Now you created a project .The project folder contains all of your sources and project metadata, such as the project Ant script.
  6. Right-click the defaultPackage node in the Explorer window and choose New > MIDlet
  7. Enter HelloMIDlet as the MIDlet name. Click Finish. TheHelloMIDlet.java file is created and the source code is displayed in the IDE's Editor window.
  8. Now add the code following code in the existing code.
    import javax.microedition.lcdui.*;
    /**
      * @author Abbas*/
      public class HelloWorld extends MIDlet implements CommandListener{
      Form form;
      Command exit;
      StringItem text;
      Display disp;
      public void startApp() {
      disp=Display.getDisplay(this);
      initilize();
      disp.setCurrent(form);}
      public void pauseApp() {}
      public void destroyApp(boolean unconditional) {}
      public void initilize(){
      form=new Form("HELLO WORLD");
      text=new StringItem("Hai How are u?","Bye",StringItem.PLAIN);
      exit=new Command("Exit",Command.EXIT,1);
      form.append(text);
      form.addCommand(exit);
      form.setCommandListener(this);}
      public void commandAction(Command cc,Displayable dd)
      {
      if(cc==exit)
      {
      destroyApp(true);
      notifyDestroyed();
      } }}

      Thats all ... Now you can run the Application
      1. Right Click the Project Folder and Choose the Run. Or Press F6.
      2. If you done any changes , Use F9 to complie and F6 run.
      Now Create sucesfully created a Hellow World J2ME Application in one of Two Ways

      Creating using Visual Mobile Designer is Another way to create application.





      1 comment:

      1. hi ur explaination was simple n helpful to me as im new to j2me but can i know how send a text message from mobile application to a system using j2me

        ReplyDelete