Mobile Application Programming LAB
Mobile Application Programming LAB
Mobile Application Programming LAB
APPLICATION
PROGRAMMING
LAB
CONTENT
2 SIMPLE CALCULATOR
3 CALENDAR
4 TIMER
5 SIMPLE GAME
6 ANIMATION IMAGE
7 PERSONAL PHONEBOOK
8 AUTHENTICATION AND
ENCRYPTION TECHNIQUE
10 STUDY OF GLOMOSIM
SIMULATOR
EX.NO: 1
DATE:
AIM:
To study about WML and J2ME simulator.
WML TAGS
WAP homepages are not very different from HTML homepages.
The markup language used for WAP is WML (Wireless Markup Language).
WML uses tags just like HTML - but the syntax is stricter and conforms to the
XML 1.0 standard. WML pages have the extension *.WML, just like HTML
pages have the extension *.HTML
CONCLUSION
WAP is programmed in wireless markup language WML (application
of XML) and WMLScript (WAP's version JavaScript) which is embedded in
client's mobile. WML provides a simple event mechanism that allows different
content to be displayed. User actions, such as pressing a key, can be tied to
scripts that cause changes in content. The WML browser also has this timer
function that can load a different page or trigger the change of variables when
the time is up. This provide great flexibility than the static content that HTML
can deliver.
EX.NO: 2
DATE:
SIMPLE CALCULATOR
AIM:
To write the program for implementing the simple calculator having +, -,
* and / using J2ME.
ALGORITHM:
package hello;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class Midlet extends MIDlet implements CommandListener {
Display dis;
Form frm;
TextField x,y;
Command add,sub,mul,div,clr;
StringItem res;
public void startApp() {
dis=Display.getDisplay(this);
frm=new Form("Calculator");
add=new Command("Addition",Command.ITEM,1);
sub=new Command("Subtraction",Command.ITEM,1);
mul=new Command("Multiply",Command.ITEM,1);
div=new Command("Division",Command.ITEM,1);
clr=new Command("Clear",Command.ITEM,1);
x=new TextField("Enter the value","",30,1);
y=new TextField("Enter the value","",30,1);
frm.addCommand(add);
frm.addCommand(sub);
frm.addCommand(mul);
frm.addCommand(div);
frm.addCommand(clr);
frm.append(x);
frm.append(y);
res=new StringItem("Result","");
frm.append(res);
frm.setCommandListener(this);
dis.setCurrent(frm);
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
public void commandAction(Command c, Displayable d) {
String m=c.getLabel();
if(m.equals("Addition"))
{
int a,b;
a=Integer.parseInt(x.getString());
b=Integer.parseInt(y.getString());
res.setLabel("addition");
res.setText("Result"+(a+b));
}
else
if(m.equals("Subtraction"))
{
int a,b;
a=Integer.parseInt(x.getString());
b=Integer.parseInt(y.getString());
res.setLabel("Subtraction");
res.setText("Result"+(a-b));
}
else
if(m.equals("Multiply"))
{
int a,b;
a=Integer.parseInt(x.getString());
b=Integer.parseInt(y.getString());
res.setLabel("Multiply");
res.setText("Result"+(a*b));
}
else
if(m.equals("Division"))
{
int a,b;
a=Integer.parseInt(x.getString());
b=Integer.parseInt(y.getString());
res.setLabel("Division");
res.setText("Result"+(a/b));
}
else
{
x.setString("");
y.setString("");
}
}
}
OUTPUT:
RESULT:
Thus the program for implementing the calculator in mobile was
successfully executed and verified.
EX.NO: 3
DATE:
CALENDAR
AIM:
To write the program for implementing the calendar for any given month
and year using J2ME.
ALGORITHM:
TIMER
AIM:
To write the program for implementing the Timer to System Time using
J2ME.
ALGORITHM:
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import java.util.Timer;
import java.util.TimerTask;
import java.util.*;
public class Midlet extends MIDlet implements
CommandListener,ItemStateListener {
Display dis;
Form frm;
Command snooze,reset,exit;
DateField dfsnoozetime;
int dateindex;
Date currentdate;
Timer tmsnooz;
snoozeTimer Timerttsnooze;
boolean dateOK=false;
public Midlet()
{
dis=Display.getDisplay(this);
frm=new Form("timer");
currentdate=new Date();
dfsnoozetime=new DateField("",DateField.DATE_TIME);
dfsnoozetime.setDate(currentdate);
snooze=new Command("snooze",Command.SCREEN,1);
reset=new Command("reset",Command.SCREEN,1);
exit=new Command("exit",Command.EXIT,1);
dateindex=frm.append(dfsnoozetime);
frm.addCommand(snooze);
frm.addCommand(reset);
frm.addCommand(exit);
frm.setCommandListener(this);
frm.setItemStateListener(this);
}
public void startApp()
{
dis.setCurrent(frm);
}
public void ItemStatechanged(Item i)
{
if(i==dfsnoozetime)
{
if(dfsnoozetime.getDate().getTime()<currentdate.getTime())
{
dateOK=false;
}
else
{
dateOK=true;
}
}
}
public void CommandAction(Command c,Displayable d)
{
if(c==snooze)
{
if(dateOK=false)
{
Alert al=new Alert("Unable to set Alerms");
al.setTimeout(Alert.FOREVER);
al.setType(AlertType.ERROR);
dis.setCurrent(al);
}
else
{
tmsnooz=new Timer();
Timerttsnooze=new snoozeTimer();
long amount=dfsnoozetime.getDate().getTime()-
currentdate.getTime();
tmsnooz.schedule(Timerttsnooze,amount);
frm.removeCommand(snooze);
frm.removeCommand(reset);
frm.delete(dateindex);
frm.setTitle("snooze...");
}
}
else if(c==reset)
{
dfsnoozetime.setDate(currentdate=new Date());
}
else if(c==exit)
{
destoryApp(false);
notifyDestroyed();
}
}
SIMPLE GAME
AIM:
To write the program for implementing simple game using J2ME.
ALGORITHM:
package game;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
import java.util.Random;
ANIMATION
AIM:
To write the program for implementing the calendar for any given month
and year using J2ME.
ALGORITHM:
AIM:
To write the program for implementing the personal phonebook
containing the name,phone no,address,e-mail using J2ME.
ALGORITHM:
import javax.microedition.io.CommConnection;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
import javax.microedition.rms.*;
public class Midlet extends MIDlet implements CommandListener{
private Display display;
private ChoiceGroup searchgroup;
private Form searchform;
private TextField searchtextField;
private Command exitcmd;
private Command searchcmd;
private Command addContactcmd;
private Form addcontactForm;
private TextField nametxtField,numberTextField;
private Command backcmd;
private Command saveCmd;
private String nameStr;
private String numberStr;
private Alert addalert;
private RecordStore openRecStore;
public void startApp() {
display=Display.getDisplay(this);
searchform=new Form("Search Contact");
searchtextField=new TextField("Search Here", "", 30,TextField.ANY);
searchform.append(searchtextField);
searchgroup=new ChoiceGroup("",Choice.EXCLUSIVE);
searchform.append(searchgroup);
exitcmd=new Command("Exit",Command.EXIT,7);
searchform.addCommand(exitcmd);
addContactcmd=new Command("Add",Command.OK,4);
searchform.addCommand(addContactcmd);
searchcmd=new Command("Search", Command.ITEM, 2);
searchform.addCommand(searchcmd);
searchform.setCommandListener(this);
display.setCurrent(searchform);
addcontactForm=new Form("Add Contact");
nametxtField=new TextField("Name","", 80,TextField.ANY);
numberTextField=new TextField("Number","",80,
TextField.PHONENUMBER);
addcontactForm.append(nametxtField);
addcontactForm.append(numberTextField);
backcmd=new Command("Back",Command.BACK,2);
addcontactForm.addCommand(backcmd);
saveCmd=new Command("Save",Command.OK,4);
addcontactForm.addCommand(saveCmd);
addcontactForm.setCommandListener( this);
try
{
openRecStore=RecordStore.openRecordStore("Contacts", true);
}catch(RecordStoreException ex){ex.printStackTrace();}
loadcontact();
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) { }
if(c==exitcmd)
{
notifyDestroyed();
}else if(c==addContactcmd)
{
nametxtField.setString("");
numberTextField.setString("");
display.setCurrent(addcontactForm);
}
else if (c==backcmd)
{
searchtextField.setString("");
display.setCurrent(searchform);
}
else if (c==saveCmd)
{
nameStr=nametxtField.getString();
numberStr=numberTextField.getString();
addalert=new Alert("Added to the Contact");
loadcontact();
display.setCurrent(addalert,searchform);
searchtextField.setString("");
String fulldetail=nameStr+"*"+numberStr;
byte[] bytearray=fulldetail.getBytes();
try
{
openRecStore.addRecord(bytearray, 0, fulldetail.length());
}
catch(RecordStoreException ex){ex.printStackTrace();}
loadcontact();
}
else if (c==searchcmd)
{
addalert=new Alert("Search Found");
searchcontact(searchtextField.getString().toString());
display.setCurrent(addalert,searchform);
searchtextField.setString("");
}
}
public void loadcontact()
{
searchgroup.deleteAll();
try
{
RecordEnumeration enuRec=openRecStore.enumerateRecords(null,
null, true);
while(enuRec.hasNextElement())
{
try
{
byte[] nextrec=enuRec.nextRecord();
String nextRecStr=new String(nextrec);
String takename=nextRecStr.substring(0,nextRecStr.indexOf("*"));
Stringtakenumber=nextRecStr.substring(nextRecStr.indexOf("*")+1
,nextRecStr.length());
searchgroup.append(takename+"-"+takenumber, null);
}
catch(RecordStoreException ex){ex.printStackTrace();}
}
}
catch(RecordStoreException ex){ex.printStackTrace();}
}
public void searchcontact(String str)
{
searchgroup.deleteAll();
try
{
RecordEnumeration enuRec=openRecStore.enumerateRecords(null,
null, true);
while(enuRec.hasNextElement())
{
try
{
byte[] nextrec=enuRec.nextRecord();
String nextRecStr=new String(nextrec);
String takename=nextRecStr.substring(0,nextRecStr.indexOf("*"));
String takenumber=nextRecStr.substring(nextRecStr.indexOf("*")+1
,nextRecStr.length());
if(str.equalsIgnoreCase(takename))
{
searchgroup.append(takename+"-"+takenumber, null);
}
}
catch(RecordStoreException ex){ex.printStackTrace();}
}
}
catch(RecordStoreException ex){ex.printStackTrace();}
}
}
OUTPUT:
RESULT:
Thus the program for implementing the animation in mobile was
successfully executed and verified.
EX.NO: 8
DATE:
AIM:
To write the program for implementing the authentication and encryption
technique used in GSM.
ALGORITHM:
package encryption;
import javax.microedition.lcdui.*;
import javax.microedition.lcdui.TextField;
import javax.microedition.midlet.*;
public class Midlet extends MIDlet implements CommandListener{
StringItem s;
Form f;
Display disply;
TextField txt1;
public void startApp() {
disply=Display.getDisplay(this);
f=new Form("Encryption/Decryption(Character)");
txt1=new TextField("Plain Text", "", 20, 0);
Command encrypt,decrypt;
encrypt=new Command("Encrypt",Command.ITEM, 1);
decrypt=new Command("Decrypt",Command.ITEM, 2);
f.append(txt1);
f.addCommand(encrypt);
f.addCommand(decrypt);
s=new StringItem("Result", "");
f.append(s);
f.setCommandListener(this);
disply.setCurrent(f);
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
public void commandAction(Command c, Displayable d) {
String k=c.getLabel();
if(k.equalsIgnoreCase("Encrypt"))
{
f=new Form("Encryption/Decryption");
String res=en(txt1.getString());
s=new StringItem("Encrypt Result", res);
f.append(s);
disply.setCurrent(f);
}
if(k.equalsIgnoreCase("Decrypt"))
{
f=new Form("Encryption/Decryption");
s=new StringItem("Decrypt Result",
""+de(Integer.parseInt(txt1.getString())));
f.append(s);
disply.setCurrent(f);
}
}
String en(String x)
{
String m="";
for(int i=0;i<x.length();i++)
{
m=m+"-"+getkey(x.charAt(i));
}
return m;
}
AIM:
To write the program for browsing the internet using mobile phone
simulator.
ALGORITHM:
import java.io.*;
import javax.microedition.io.*;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
AIM:
To study the concept of Glomo sim Simulator.
INTRODUCTION TO GLOMOSIM:
1. Introduction
#
SIMULATION-RANGE-X 100
SIMULATION-RANGE-Y 100
#
# Number of partitions in x and y range.
PARTITION-NUM-X 2
PARTITION-NUM-Y 2
#
We would now have a simulation are of size (100 * 100). We would also have 4
partitions (each partition is represented by a single entity) in the simulation. So
one partition would encompass the square area represented by the coordinates
(0, 0), (49, 0), (0, 49), and (49, 49).
1.2 Layered Structure
Since we are building GloMoSim using a layered approach, we would like to
have the ability to rapidly integrate models developed at different layers by
different people. Hence the simple approach here would seem to be that each
layer in the simulation would be represented by a different Parsec entity. We
would still have the same problem that we had previously. As the number of
layers in the simulation increases, the number of entities in the simulation
would also increase. This would lead to scalability and performance problems in
the simulation. But this is not as dramatic since there are only a few layers in
the simulation. But there are other reasons why we need to aggregate the layers
into a single entity.
CONCLUSION:
Here the glomo simulator has been evaluated with the range of small
time manipulation. So every part of delivery standards can be modified easily.