J2ME PROGRAMS

1

Hello World
import javax.microedition.lcdui.*; import javax.microedition.midlet.*; public class HelloWorldJ2MEStyle_Eg extends MIDlet implements CommandListener { private Display disp; private TextBox tb; private Command cmd_exit; private Command cmd_start; private Form frm; public HelloWorldJ2MEStyle_Eg() { disp=Display.getDisplay(this); tb = new TextBox("VIKRANT MIDlet Corner","Hello!! \n Welcome to the Exciting World of J2ME",100,0); cmd_exit = new Command("EXIT",Command.SCREEN,1); cmd_start = new Command("START",Command.SCREEN,1); frm = new Form("VIKRANT MIDLET CORNER"); //frm.addCommand(tb); frm.addCommand(cmd_exit); frm.addCommand(cmd_start); frm.setCommandListener(this); } public void startApp() { disp.setCurrent(frm); } public void pauseApp() { } public void destroyApp(boolean unconditional) { } public void commandAction(Command cmd,Displayable displayable) { if(cmd == cmd_start) { disp.setCurrent(tb); }

2

if(cmd == cmd_exit) { destroyApp(false); notifyDestroyed(); } } }

3

4

5

Phone Color Status package colorcheck; import javax.microedition.midlet.*; import javax.microedition.lcdui.*; /*** @author VBAINS ***/ public class ColorAttribute extends MIDlet implements CommandListener { private Display disp; private TextBox txtbox; private Form frm; private Command cmd_exit; public ColorAttribute() { disp=Display.getDisplay(this); cmd_exit=new Command("Exit",Command.SCREEN,1); String msg=null; if(disp.isColor()) { msg="Yahoo!! Colored Phone"; } else { msg="Sorry yaar Not Colored Phone"; } txtbox=new TextBox("Vikrant Check Color",msg,30,0); txtbox.addCommand(cmd_exit); txtbox.setCommandListener(this); } public void startApp() { disp.setCurrent(txtbox); } public void pauseApp() { }

6

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

}

7

8