Professional Documents
Culture Documents
PRACTICAL FILE
ON
MOBILE COMPUTING
SUBMITTED FOR
BACHELOR OF TECHNOLOGY
IN
COMPUTER SCIENCE AND ENGINEERING
AT
SUBMITTED TO SUBMITTED BY
MS. NAMITA JAIN Shivani Bansal
Asst. Professor CSE CSE-IVth Year (8th SEM)
Roll NO.- Cse/17/232
INDEX
INTRODUCTION OF 20/04/2021
1 J2ME
04/05/2021
2 Write a J2ME
program to
implement a
Calculator with add,
subtract, multiply and
division functions
(Use buttons).
J2ME stands for Java 2, Micro Edition. It is a stripped-down version of Java targeted at devices which
have limited processing power and storage capabilities and intermittent or fairly low-bandwidth
network connections. These include mobile phones, pagers, wireless devices and set-top boxes
among others.
Profiles
Configurations
A configuration defines the minimum Java technology that an application developer can expect on a
broad range of implementing devices.
specifies the Java environment for mobile phone, pager and wireless devices
describes the Java environment for digital television set-top boxes, high end wireless devices and
automotive telematics systems.
These two configurations differ only in their respective memory and display capabilities.
What is a J2ME Profile?
A specification layer above the configuration which describes the Java configuration for a specific
vertical market or device type.
J2ME Profiles
this is the application environment for wireless devices based on the CLDC
these are profiles for devices based on the CDC, which are not addressed in this tutorial
Virtual Machines
The CLDC and the CDC each require their own virtual machine because of their different memory
and display capabilities. The CLDC virtual machine is far smaller than that required by the CDC and
supports less features. The virtual machine for the CLDC is called the Kilo Virtual Machine (KVM) and
the virtual machine for the CDC is called the CVM.
INSTALLIATION OF J2ME
2. Verify that you have an installation of Java Standard Edition Development Kit (JDK) 6 or later.
Now that you have a JDK installed, you are ready to install J2ME 2.5.2
3. Download the Sun Java Wireless Toolkit 2.5.2 for CLDC from here: http://www.rose-
hulman.edu/class/csse/binaries/csmobilegames/sun_java_wireless_toolkit-2.5.2_01-win.exe
1. Find the Required File you downloaded in step 3 above and double click it to run it.
You may get a message that says "The publisher could not be verified. Are you sure
you want to run this software?"
Ignore the warning and run it by clicking the Run button. It will not harm your
system.
4. You will now be asked to choose your Java [TM] Virtual Machine Location. Accept
the default or browse to the location of your choice JVM.
8. Select a Program (start menu) Folder the installation (or again, accept the default).
10. Make sure the box is selected to Check for Product Updates and click the Next
button.
11. When asked to Start Copying Files, click the Next button.
12. Wait a couple minutes while it installs the updates, then click the Finish
button. That completes your installation.
Now that you have a Java Wireless Toolkit installed on your machine, you can open existing projects,
create new projects, and run them on a mobile device emulator or on an actual physical device.
Follow the instructions below for opening an existing project and running it in a mobile device
emulator.
1. Locate the Sun Java (TM) Wireless Toolkit 2.5.2_01 for CLDC Folder on your Windows
Machine. You can do this by clicking on Start Menu → All Programs, and scrolling to the
folder.
3. Click Open Project and select from the list of available projects.
5. Click the Run button and voila! You are now ready to run the selected application on your
mobile device emulator.
6. Select from the games provided (e.g., Bouncing Ball). Select a background of your choice
and have fun with it.
PROGRAM 2
import javax.microedition.lcdui.*;
import javax.microedition.midlet.MIDlet;
if (isInitialized)
return;
}
f.append(t1);
f.append(t2);
itema.setDefaultCommand(add);
itema.setItemCommandListener(this);
f.append(itema);
items.setDefaultCommand(sub);
items.setItemCommandListener(this);
f.append(items);
itemm.setDefaultCommand(mul);
itemm.setItemCommandListener(this);
f.append(itemm);
itemd.setDefaultCommand(div);
itemd.setItemCommandListener(this);
f.append(itemd);
f.append(tr);
f.addCommand(exitCmd);
f.setCommandListener(this);
Display.getDisplay(this).setCurrent(f);
isInitialized = true;
//do not declare variables inside try…it will give you an error
try
if (c==add)
res=n1+n2;
if (c==sub)
res=n1-n2;
if (c==mul)
res=n1*n2;
if (c==div)
res=n1/n2;
}
catch (NumberFormatException e)
return;
catch (ArithmeticException e)
alert.setString(“Divide by zero.”);
Display.getDisplay(this).setCurrent(alert);
return;
tr.setMaxSize(res_str.length());
tr.setString(res_str);
if (c == exitCmd)
destroyApp(false);
notifyDestroyed();
return;
}
}
String s = t.getString();
if (s.length() == 0)
Display.getDisplay(this).setCurrent(alert);
double n;
try
n = Double.parseDouble(s);
catch (NumberFormatException e)
Display.getDisplay(this).setCurrent(alert);
throw e;
return n;
}
OUTPUT
PROGRAM 3
Design a Calender of any given month and year using J2ME
import javax.microedition.lcdui.*;
import javax.microedition.midlet.MIDlet;
import java.util.Date;
import java.util.TimeZone;
public CalenderMIDlet(){
display = Display.getDisplay(this);
form.append(calender);
display.setCurrent(form);
notifyDestroyed();
}}
OUTPUT
PROGRAM 4
Design a Login Form using J2ME
import javax.microedition.midlet.MIDlet;
import javax.microedition.lcdui.*;
public LoginExample() {
try{
img = Image.createImage("/logo.png");
imge = Image.createImage("/front_left1_bad.png");
img2 = Image.createImage("/Congratulations-1.png");
}catch(Exception e){
System.out.println(e.getMessage());
display = Display.getDisplay(this);
try{form.append(img);}catch(Exception e){}
form.append(userName);
form.append(password);
form.addCommand(cancel);
form.addCommand(login);
form.setCommandListener(this);
display.setCurrent(form);
notifyDestroyed();
showMsg();
} else {
tryAgain();
Alert success = new Alert("Login Successfully", "Your Login Process is completed!", img2,
AlertType.INFO);
success.setImage(img2);
userName.setString("");
password.setString("");
display.setCurrent(success, form);
}
public void tryAgain() {
Alert error = new Alert("Login Incorrect", "Please try again", imge, AlertType.ERROR);
error.setTimeout(900);
error.setImage(imge);
userName.setString("");
password.setString("");
display.setCurrent(error, form);
if(label.equals("Cancel")) {destroyApp(true);
OUTPUT