0% found this document useful (0 votes)
33 views

First 3pgms

The document contains code examples for several common Java ME applications including: 1) A simple "Hello World" app that prints a message to the console. 2) An app with text fields to collect a name and phone number and display the input. 3) A command example app that demonstrates using commands to trigger actions. 4) A phone book app that allows the user to enter and view contacts. 5) A login example app with validation of username and password fields.

Uploaded by

msksaran
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views

First 3pgms

The document contains code examples for several common Java ME applications including: 1) A simple "Hello World" app that prints a message to the console. 2) An app with text fields to collect a name and phone number and display the input. 3) A command example app that demonstrates using commands to trigger actions. 4) A phone book app that allows the user to enter and view contacts. 5) A login example app with validation of username and password fields.

Uploaded by

msksaran
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 8

HelloWorld

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

public class HelloMIDlet extends MIDlet { public void startApp() { S stem.out.println(!Hello "orld!); # public void pauseApp() { # public void destro App(boolean unconditional) { # #

OR

import javax.microedition.lcdui.*;
import javax.microedition.midlet.*; public class HelloWorld extends MIDlet{ private Form form; private Display display; public HelloWorld !{ super !; " public void start#pp !{ form $ ne% Form &Hello World&!; 'trin( ms( $ &Hello World)))))))&; form.append ms(!; display $ Display.(etDisplay t*is!; display.set+urrent form!; " public void pause#pp !{" public void destroy#pp boolean unconditional!{ notifyDestroyed !; " "

TextFieldExample import javax.microedition.lcdui.*;


import javax.microedition.midlet.*; public class ,extField-xample extends MIDlet implements +ommand.istener{ private Form form; private Display display; private ,extField name/ company; private +ommand o0; public ,extField-xample !{ name $ ne% ,extField &1ame2&/ &&/ 34/ ,extField.#15!; company $ ne% ,extField &+ompany 1ame2&/ &&/ 34/ ,extField.#15!; o0 $ ne% +ommand &67&/ +ommand.67/ 8!; " public void start#pp !{ display $ Display.(etDisplay t*is!; Form form $ ne% Form &,ext Field&!; form.append name!; form.append company!; form.add+ommand o0!; form.set+ommand.istener t*is!; display.set+urrent form!; " public void pause#pp !{ " public void destroy#pp boolean destroy!{ notifyDestroyed !; " public void s*o%Input !{ display $ Display.(etDisplay t*is!; 'trin( n $ name.(et'trin( !; 'trin( c $ company.(et'trin( !; Form form $ ne% Form &Input 9alue&!; form.append n!; form.append c!; display.set+urrent form!; "

public void command#ction +ommand c/ Displayable d! { 'trin( label $ c.(et.abel !;

if label.e:uals &67&!!{ s*o%Input !; " " "

CommandExample import javax.microedition.lcdui.*; import javax.microedition.midlet.*; public class CommandExample extends MIDlet implements CommandListener{ private Form form; private Displa displa ; private Command o!" bac!" cancel" exit" #elp" item" screen" stop; public CommandExample$%{ form & ne' Form$(Command Form(%; screen & ne' Command$()C*EE+(" Command.)C*EE+" ,%; bac! & ne' Command$(-.C/(" Command.-.C/" 0%; cancel & ne' Command$(C.+CEL(" Command.C.+CEL" 1%; o! & ne' Command$(2/(" Command.2/" 3%; #elp & ne' Command$(4EL5(" Command.4EL5" 6%; stop & ne' Command$()725(" Command.)725" 8%; exit & ne' Command$(E9I7(" Command.E9I7" :%; item & ne' Command$(I7EM(" Command.I7EM" ;%; < public void start.pp$%{ displa & Displa .=etDispla $t#is%; form.addCommand$screen%; form.addCommand$bac!%; form.addCommand$cancel%; form.addCommand$o!%; form.addCommand$#elp%; form.addCommand$stop%; form.addCommand$exit%; form.addCommand$item%; form.setCommandListener$t#is%; displa .setCurrent$form%; < public void pause.pp$%{< public void destro .pp$boolean destro %{ notif Destro ed$%;

< public void bac!Com$%{ .lert bac! & ne' .lert$(-.C/ Command(" (-ac! Command Executed>(" null" .lert7 pe.I+F2%; bac!.set7imeout$6???%; displa .setCurrent$bac!" form%; < public void o!Com$%{ .lert o! & ne' .lert$(2/ Command(" (2/ Command Executed>(" null" .lert7 pe.I+F2%; o!.set7imeout$6???%; displa .setCurrent$o!" form%; < public void cancelCom$%{ .lert cancel & ne' .lert$(C.+CEL Command(" (Cancel Command Executed>(" null" .lert7 pe.I+F2%; cancel.set7imeout$6???%; displa .setCurrent$cancel" form%; < public void exitCom$%{ .lert exit & ne' .lert$(E9I7 Command(" (Exit Command Executed>(" null" .lert7 pe.I+F2%; exit.set7imeout$6???%; displa .setCurrent$exit" form%; < public void command.ction$Command c" Displa able d% { )trin= label & c.=etLabel$%; if$label.e@uals$(-.C/(%%{ bac!Com$%; < else if$label.e@uals$(2/(%%{ o!Com$%; < else if$label.e@uals$(C.+CEL(%%{ cancelCom$%; < else if$label.e@uals$(E9I7(%%{ exitCom$%; < < <

PhoneBookExample

import javax.microedition.lcdui.*; import javax.microedition.midlet.*; public class 5#one-oo!Example extends MIDlet implements CommandListener { private Command exit" next" +e'; private 7ext-ox name" number; private Displa displa ; private )trin= nam" no; private Form form; public 5#one-oo!Example$%{ next & ne' Command$(+ext(" Command.)C*EE+" 0%; exit & ne' Command$(Exit(" Command.)C*EE+" 0%; +e' & ne' Command$(+e'(" Command.)C*EE+" 0%; < public void start.pp$%{ displa & Displa .=etDispla $t#is%; name & ne' 7ext-ox$(Enter +ame(" ((" 1?" 7extField..+A%; name.addCommand$next%; name.setCommandListener$t#is%; number & ne' 7ext-ox$(Enter +umber(" ((" ,1" 7extField.542+E+BM-E*%; number.addCommand$+e'%; number.addCommand$exit%; number.setCommandListener$t#is%; displa .setCurrent$name%; < public void pause.pp$% {< public void destro .pp$boolean unconditional%{ notif Destro ed$%; < public void command.ction$Command c" Displa able s%{ )trin= label & c.=etLabel$%; if $label.e@uals$(Exit(%%{ nam & name.=et)trin=$%; no & number.=et)trin=$%; ) stem.out.println$(+ame & ( C name.=et)trin=$% C (" +umber & (C number.=et)trin=$%%; destro .pp$false%;

< else if $label.e@uals$(+ext(%%{ number.set)trin=$((%; displa .setCurrent$number%; < else if $label.e@uals$(+e'(%%{ displa .setCurrent$name%; nam & name.=et)trin=$%; no & number.=et)trin=$%; ) stem.out.println$(+ame & ( C name.=et)trin=$% C (" +umber & (C number.=et)trin=$%%; name.set)trin=$((%; < < <

LoginExample import javax.microedition.midlet.MIDlet; import javax.microedition.lcdui.*; public class Lo=inExample extends MIDlet implements CommandListener{ private Displa displa ; private 7extField user+ame"pass'ord; public Form form; private Command lo=in"cancel; private Ima=e im=" im=e" im=0; public Lo=inExample$% { form & ne' Form$()i=n in(%; user+ame & ne' 7extField$(Lo=inIDD(" ((" 1?" 7extField..+A%; pass'ord & ne' 7extField$(5ass'ordD(" ((" 1?" 7extField.5.))E2*D%; cancel & ne' Command$(Cancel(" Command.C.+CEL" 0%; lo=in & ne' Command$(Lo=in(" Command.2/" 0%; tr { im= & Ima=e.createIma=e$(Flo=o.pn=(%; im=e & Ima=e.createIma=e$(FfrontGleft,Gbad.pn=(%; im=0 & Ima=e.createIma=e$(FCon=ratulationsH,.pn=(%; <catc#$Exception e%{ ) stem.out.println$e.=etMessa=e$%%; < < public void start.pp$% { displa & Displa .=etDispla $t#is%; tr {form.append$im=%;<catc#$Exception e%{< form.append$user+ame%;

form.append$pass'ord%; form.addCommand$cancel%; form.addCommand$lo=in%; form.setCommandListener$t#is%; displa .setCurrent$form%; < public void pause.pp$% {< public void destro .pp$boolean unconditional% { notif Destro ed$%; < public void validateBser$)trin= name" )trin= pass'ord% { if $name.e@uals$(sandeep(% II pass'ord.e@uals$(sandeep(%% { s#o'Ms=$%; < else { tr .=ain$%; < < public void s#o'Ms=$% { .lert success & ne' .lert$(Lo=in )uccessfull (" (Aour Lo=in 5rocess is completed>(" im=0" .lert7 pe.I+F2%; success.setIma=e$im=0%; user+ame.set)trin=$((%; pass'ord.set)trin=$((%; displa .setCurrent$success" form%; < public void tr .=ain$% { .lert error & ne' .lert$(Lo=in Incorrect(" (5lease tr a=ain(" im=e" .lert7 pe.E**2*%; error.set7imeout$J??%; error.setIma=e$im=e%; user+ame.set)trin=$((%; pass'ord.set)trin=$((%; displa .setCurrent$error" form%; < public void command.ction$Command c" Displa able d% { )trin= label & c.=etLabel$%; if$label.e@uals$(Cancel(%% { destro .pp$true%; < else if$label.e@uals$(Lo=in(%% {

validateBser$user+ame.=et)trin=$%" pass'ord.=et)trin=$%%; < < <

You might also like