Tuesday, September 14, 2010

mc lab manual 2nd expt

Experiment No.2

Experiment Name: MIDlet for Simple Hello world Program.

Resources Required:

a . Equipments/Machines:

PIII 810 MHz, 20 GB HDD, 128 MB RAM, 1.44 FDD

14” color Monitor, 101 Keyboard, Serial mouse, LAN card

Dot matrix printer.

S/W : Sun Java Wireless Toolkit , Java

b . Consumables: Printer pages for printouts.

Theory:

MIDlets vs Applets

MIDlets are applets for mobile phones. Just like applets, they run in a protected sandbox - the KVM - but unlike applets, they are extremely limited. MIDP 1.0 is currently found on most Java-capable phones and is fairly restrictive. As an example - the KVM doesn't allow you to process floating point numbers yet and MIDlets written for MIDP 1.0 can't access anything outside of the sandbox without proprietary APIs from phone manufacturers. So, put your dreams of developing the ultimate MIDlet with hooks into every part of your phone OS on the backburner for a while. We're going to write our first MIDlet - a full-featured "Hello MIDlet" application.

Simple HelloMIDlet

We're going to use a program called Ktoolbar from the JAVA WTK which we installed earlier.

  • Go to Start->Programs->J2ME Wireless Toolkit 2.1->KToolbar.
  • Click on the New Project button and name your project HelloProject and your MIDlet HelloMidlet.
  • Once you press Create Project, KToolbar will create a bunch of directories for your project in the apps subdirectory. We're going to ignore most of them for the moment and focus on a few important ones

C:\j2mewtk\apps\HelloProject - the main directory for your project
C:\j2mewtk\apps\HelloProject\bin - where Ktoolbar stores .jar, .jar and manifest.mf files
C:\j2mewtk\apps\HelloProject\classes - where the class files are stored
C:\j2mewtk\apps\HelloProject\src - where the source .java files are stored

Code For HelloMidlet.java :-

import javax.microedition.lcdui.*;

import javax.microedition.midlet.*;

public class HelloMidlet

extends MIDlet

implements CommandListener {

private Form mMainForm;

public HelloMidlet() {

mMainForm = new Form("HelloMidlet");

mMainForm.append(new StringItem(null, "Hello, MIDP! \n\nYou and me - we're gonna make sweet MIDlets together! "));

mMainForm.addCommand(new Command("Exit", Command.EXIT, 0));

mMainForm.setCommandListener(this);

}

public void startApp() {

Display.getDisplay(this).setCurrent(mMainForm);

}

public void pauseApp() {}

public void destroyApp(boolean unconditional) {}

public void commandAction(Command c, Displayable s) {

notifyDestroyed();

}

}



Conclusion : Thus we have implemented simple hello MIDlet.

No comments:

 

Free HTML Hit Counters

Locations of visitors to this page