Mobile Computing
Mobile
computing is human–computer
interaction by which a computer is
expected to be transported during normal usage,
which allows for transmission of data, voice and video. Mobile computing
involves mobile communication, mobile hardware, and mobile software.
Communication issues include ad hoc networks and infrastructure networks as well as communication
properties, protocols, data formats and concrete technologies. Hardware includes mobile devices or device
components. Mobile software deals with the characteristics and requirements of
mobile applications.
Devices
o
Portable
computers, compact, lightweight units including a full character set keyboard
and primarily intended as hosts for software that may be parameterized, as laptops,
notebooks, notepads, etc.
o
Mobile phones, including a restricted key set primarily intended but not
restricted to for vocal communications, as smartphones, cell phones, feature
phones, etc.
o
Smart cards that can run multiple applications but typically
payment, travel and secure area access
o
Wearable computers, mostly limited to functional keys
and primarily intended as incorporation of software agents, as watches, wristbands, necklaces, keyless implants, etc.
MIDlet
A MIDlet is an application that uses the Mobile Information Device Profile (MIDP) of the Connected Limited Device
Configuration (CLDC) for the Java ME environment. Typical applications
include games running on mobile devices and cell phones which have small graphical displays,
simple numeric keypad interfaces and limited network access over HTTP.
J2ME
Java Platform, Micro Edition or Java
ME is a computing platform for development and deployment of portable code for embedded
and mobile
devices (micro-controllers,
sensors, gateways, mobile phones, personal digital assistants, TV set-top
boxes, printers). Java ME was formerly known as Java 2 Platform, Micro Edition or J2ME.
The
platform uses the object-oriented Java programming
language. It is part of the Java software-platform family. Java ME was designed by Sun
Microsystems, acquired by Oracle Corporation in 2010; the platform replaced a
similar technology, PersonalJava.
javax.microedition.io
Contains the Java
ME-specific classes used for I/O operations.
javax.microedition.lcdui
Contains the Java
ME-specific classes used for the GUI.
LCDUI
has a simple screen based approach where a single Displayable is always active
at a time in the application user interface. LCDUI API provides a small set of
displayables common in mobile device user interfaces: List, Alert, TextBox,
Form and Canvas. For all displayables the device MIDP implementation has
control over the presentation and layout of the displayable.
LCDUI
also has a quite unique approach of abstract operations, called Commands. The
placement of commands added to a displayable is completely up to the device
implementation of this toolkit. The application programmer uses API specified
command types to indicate the usage or purpose of the command in an application
user interface. Common types are BACK, EXIT, ITEM, SCREEN.
MIDP
Mobile Information Device Profile (MIDP) is a specification published for the use
of Java on embedded devices such as mobile phones and PDAs. MIDP is part of the Java
Platform, Micro Edition (Java
ME) framework and sits on top of Connected
Limited Device Configuration (CLDC),
a set of lower level programming interfaces. MIDP was developed under the Java Community
Process. The first MIDP devices were
launched in April 2001.
CDC
Connected device
configuration (CDC) is a set of standards,
libraries, and virtual-machine features serving as the basis for application
programming interfaces (APIs) targeted at consumer and embedded devices like
smart communicators, high end PDAs, and set-top boxes. The CDC supports three
sets of APIs known as the foundation profile, personal basis profile, and
personal profile.
CLDC
The Connected
Limited Device Configuration (CLDC)
is a specification of a framework for Java ME applications
describing the basic set of libraries and virtual-machine features that must be
present in an implementation. The CLDC is combined with one or more profiles to
give developers a platform for building applications on embedded devices with
very limited resources such as pagers and mobile phones
Java ME embedded API from ORACLE
Java ME
embedded is based on the Connected Device Configuration
subset of Java Platform, Micro Edition. It is
designed to be used on systems with at least 8 MB of RAM, and can work on Linux ARM,
PowerPC, or MIPS
architecture.
The offering of
Java for embedded devices is growing fast with a large ecosystem of companies
that provide Embedded Java virtual machines for ARM
MCU based Cortex-M serie (such as ST, Freescale, Renesas, NXP), and MPU based
solution (such as TI, Renesas, Freescale).
Embedded Java
minimal requirements starts at only 30KB of (internal) flash and less than 2KB
of (internal) RAM. In order to save Bill Of Material, most Embedded Java
engines execute code in place, which avoids copying the code in RAM.
METHODS IN MIDlet DISPLAY CLASS
MIDlets
can be pure background applications or applications interacting with the
user. Interactive applications can get
access to the display by obtaining an instance of the Display class.A MIDlet
can get its Display instance by calling Display.getDisplay
(MIDlet midlet), where the MIDlet itself is given as parameter.The Display
class and all other user interface classes of MIDP are located in the package javax.microedition.lcdui.The Display
class provides a setCurrent() method
that sets the current display content of the MIDlet. The actual device screen
is not required to reflect the MIDlet display immediately the setCurrent()
method just influences the internal state of the MIDlet display and notifies
the application manager that the MIDlet would like to have the given
Displayable object displayed.The difference between Display and Displayable is
that the Display class represents the display hardware, whereas Displayable is
something that can be shown on the display.
The
MIDlet can call the isShown() method
of Displayable in order to determine whether the content is really shown on the
screen.
startApp() –
starter function of the application (entry point); it is the first function to
be executed, after the MidletHelloWorld instance has been created.
pauseApp()
– the function is executed at the occurrence of an event that involves blocking
the MIDlet application; a common scenario in a mobile device application
includes receiving a phone call during the execution of the application.
destroyApp()
– function used to close the application; it is executed at the end of the
application and contains routines used to release resources. It acts like a
destructor function.
SYNTAX
public
void startApp()
{}
public
void pauseApp()
{}
public
void destroyApp(boolean unconditional)
{}
EX.NO:01 LOGO
CREATION
AIM:
To
write a J2ME program to create the logo using paint() method.
CODING:
package
mobileapplication3;
import
javax.microedition.midlet.*;
import
javax.microedition.lcdui.*;
public
class Midlet extends MIDlet
{
private Display dis;
public
void startApp()
{
dis=Display.getDisplay(this);
dis.setCurrent(new
DrawingCanvas());
}
public
void pauseApp()
{
}
public
void destroyApp(boolean unconditional)
{
}
}
class
DrawingCanvas extends Canvas
{
public
void paint(Graphics g)
{
g.setColor(255,255,255); g.drawLine(5,4,5,195);
g.drawLine(5,195,131,282); g.drawLine(131,282,256,198);
g.drawLine(256,198,256,3); g.drawLine(256,3,130,88);
g.drawLine(130,88,5,4); g.drawLine(130,249,33,182);
g.drawLine(33,182,33,125); g.drawLine(33,125,83,90);
g.drawLine(83,90,130,121); g.drawLine(130,121,178,90);
g.drawLine(178,90,230,126); g.drawLine(230,126,230,182);
g.drawLine(230,182,130,249); g.drawLine(107,214,156,214);
g.drawLine(156,214,131,231); g.drawLine(131,231,107,214);
}
}
OUTPUT:
FORM IN J2ME
Form:
Form is an
import item to display on the screen. A form can contain other items such as
text field, command button, list, image, etc. To display
a form, first you need to create its object. Example:
Form form1=new Form("Form1");
Display:This
will create a form object named form1. The "Form1" text is the title
of the form. You can see this text at the top left corner of the form window.
To display the form on the screen you need to assign the form name as the
parameter of setCurrent method of the display object.
Display display=Display.getDisplay(this);
display.setCurrent(form1);
Text Field:TextField lets you create a text field to input a value. To put a
text field on the form you need to create text field objects. You can use the
following prototype to create a text field object:
TextField field-name=new TextField(Label, Text,Size,Constrains);
The
first argument is Label. The Label argument is used to set the text label of
the text field. The Text argument is the text to display in the text field. The
Size argument specifies the number of characters should be input in the text
field. The last argument is the text
mode. The most common used text modes are: TextField.ANY, TextField.PASSWORD,
TextField.NUMERIC, TextField.EMAILADDR, TextField.URL, TextField.UNEDITABLE. To
put the text field in the form, you can use append method of the form object.
Form_object.append(text-field-name);
Command:Command is
a useful item in every application. It tells the program to perform a specific
action when the user choose to do so. In other words, the command increases the
users' interactivity with your software. A command object can be created by
using the following prototype:
Command commadObj=new Command(Label,Type,Priority);
Label is the text to display on the command
button. The Type argument specifies the type of command. The values of the Type
argument can be Command.BACK, Command.CANCEL, Command.EXIT, Command.HELP,
Command.ITEM, Command.OK, Command.SREEN, and Command.STOP. The Priority sets
the priority of the command. If the value is 0, it is the highest priority
command. The higher the value the lower the priority is. The command can be
attached to the form by using addCommand method of the form. To enable the form
to listen to the actions that will perform by the user, you need to set the
CommandListener interface to the form by using setCommandListener method.
Form form=new
Form("Form");form.addCommand(commandObj);form.setCommandListener(this);
EX.NO:02 LOGIN
FORM IN J2ME
AIM:
To write a J2ME program to create
the login form.
package login;
import
javax.microedition.lcdui.*;
import
javax.microedition.midlet.*;
public
class Midlet extends MIDlet implements CommandListener
{
private Display display;
private
TextField username;
private
TextField password;
private
Form form;
private
Image img1,img2;
private
Command cancel;
private
Command login;
public Midlet()
{
username=new TextField("Username
: ","",10,TextField.ANY);
password=new
TextField("Password : ","",10,TextField.PASSWORD);
form=new
Form("Sign in");
cancel=new
Command("Cancel",Command.CANCEL,2);
login=new
Command("Login",Command.OK,2);
try
{
img1=Image.createImage("/welcome.png");
img2=Image.createImage("/error.jpg");
}
catch(Exception
e)
{
System.out.println(e.getMessage());
}
}
public
void startApp()
{
display=Display.getDisplay(this);
form.append(username);
form.append(password);
form.addCommand(cancel);
form.addCommand(login);
form.setCommandListener(this);
display.setCurrent(form);
}
public
void pauseApp()
{
}
public
void destroyApp(boolean unconditional)
{
notifyDestroyed();
}
public
void validateUser(String name,String password)
{
if(name.equals("anjac")&&
password.equals("anjac"))
{
menu();
}
else
{
tryAgain();
}
}
public
void menu()
{
Alert success=new Alert("Login
Successful","Proceed",img1,AlertType.INFO);
success.setImage(img1);
username.setString(null);
password.setString(null);
display.setCurrent(success,form);
}
public
void tryAgain()
{
Alert error=new Alert("Login
Failed","Please try again",img2,AlertType.INFO);
error.setImage(img2);
error.setTimeout(Alert.FOREVER);
username.setString(null);
password.setString(null);
display.setCurrent(error,form);
}
public
void commandAction(Command c, Displayable d)
{
String label=c.getLabel();
if(label.equals("Cancel"))
{
destroyApp(true);
}
else
if(label.equals("Login"))
{
validateUser(username.getString(),
password.getString());
}
}
}
OUTPUT:
EX.NO:03 CALENDAR
AIM:
Program
to Display a Calendar and Current time using J2ME.
package
calendar;
import
java.util.Calendar;
import
java.util.Date;
import
javax.microedition.midlet.*;
import
javax.microedition.lcdui.*;
public class
Midlet extends MIDlet implements CommandListener{
private Display
display;
private Date d;
Calendar c=
Calendar.getInstance();
String time;
private
DateField currentdate;
private Command
start,exit;
private Form
form;
private int
index;
public Midlet()
{
form=new
Form("Date & Time");
d=new Date();
start=new
Command("Start",Command.SCREEN,0);
exit=new
Command("Exit",Command.EXIT,0);
currentdate=new
DateField("",DateField.DATE_TIME);
currentdate.setDate(d);
}
public void
startApp()
{
form.append("Current
Time is :");
display=Display.getDisplay(this);
index =
form.append(currentdate);
form.addCommand(exit);
form.addCommand(start);
form.
setCommandListener(this);
display.setCurrent(form);
}
public void
pauseApp()
{
}
public void
destroyApp(boolean unconditional)
{
notifyDestroyed();
}
public void
commandAction(Command co, Displayable da)
{
if(co==exit){
notifyDestroyed();
}
else
if(co==start)
{
d=new Date();
c.setTime(d);
time=c.get(Calendar.HOUR_OF_DAY)+":"+c.get(Calendar.MINUTE)+":"+c.get(Calendar.SECOND);
form.append(""
+ time);
form.append("\n");
}
}
}
COMMAND
CLASS
Definition:It
illustrates how to create command button in your form. Command class build to bind
only the semantic information of the command it means command is not the
actual action its contains only information about command. Command action is
defined in CommandListener class with associated screen or
form. Command contains three methods:
·
label
·
type
·
priority
The label contains label of the
commands, the type contains types of the command and the priority contains
priority of the commands.List of the Command Field:
·
BACK
·
CANCEL
·
EXIT
·
HELP
·
ITEM
·
OK
·
SCREEN
·
STOP
Command.BACK:A navigation command that returns the user to the logically
previous screen.
Command.CANCEL:A command that is a standard negative answer to a dialog
implemented by current screen.
Command.EXIT:A command used for exiting from the application.
Command.HELP:This command specifies a request for on-line help.
Command.ITEM:With this command type the application can hint to the
implementation that the command is specific to the items of the
Screen
or the elements
of a Choice
.
Command.OK:A command that is a standard positive answer to a dialog
implemented by current screen.
Command.SCREEN:Specifies an application-defined command that pertains to the
current screen.
Command.STOP:A command that will stop some currently running process,
operation, etc.
EX.NO:04 CALCULATOR
AIM:
To
create a calculator in MIDlet using CommandListener.
package
calc;
import
javax.microedition.lcdui.*;
import
javax.microedition.midlet.*;
import
java.io.*;
public
class calc extends MIDlet implements CommandListener
{
private Form form;
private
Display display;
private
TextField input1, input2;
private
Command add, sub, mul,div;
private
StringItem item;
public
calc()
{
}
public
void startApp()
{
display = Display.getDisplay(this);
Form
form = new Form("Calculator");
form.append("Hello
everybody");
item
= new StringItem("Result", "");
input1
= new TextField("First Number:", "", 30,
TextField.NUMERIC);
input2
= new TextField("Second Number", "", 30,
TextField.NUMERIC);
form.append(input1);
form.append(input2);
add
= new Command("Addition", Command.OK, 1);
sub
= new Command("Subtraction", Command.OK, 1);
mul
= new Command("Multiplication", Command.OK, 1);
div
= new Command("Division", Command.OK, 1);
form.addCommand(add);
form.addCommand(sub);
form.addCommand(mul);
form.addCommand(div);
form.append(item);
form.setCommandListener(this);
display.setCurrent(form);
}
public
void pauseApp()
{
}
public
void destroyApp(boolean uncondn)
{
notifyDestroyed();
}
private
void calculate()
{
int
one=Integer.parseInt(input1.getString());
int
two= Integer.parseInt(input2.getString());
int
result=one+two;
item.setText(
result + "" );
}
private
void calculate1()
{
int one =
Integer.parseInt(input1.getString());
int
two = Integer.parseInt(input2.getString());
int
result = one - two;
item.setText(result
+ "");
}
private
void calculate2()
{
int one =
Integer.parseInt(input1.getString());
int
two = Integer.parseInt(input2.getString());
int
result = one * two;
item.setText(result
+ "");
}
private
void calculate3()
{
int one =
Integer.parseInt(input1.getString());
int
two = Integer.parseInt(input2.getString());
int
result = one / two;
item.setText(result
+ "");
}
public
void commandAction(Command c, Displayable d)
{
String label = c.getLabel();
if
(label.equals("Addition"))
{
calculate();
}
else
if (label.equals("Subtraction"))
{
calculate1();
}
else
if (label.equals("Multiplication"))
{
calculate2();
form.append("The
Answer is:");
}
else
if (label.equals("Division"))
{
calculate3();
form.append("The
Answer is:");
}
}
}
OUTPUT:
EX.NO:05 QUIZ
AIM:
Program
to implement mobile quiz in J2ME.
importjavax.microedition.midlet.*;
importjavax.microedition.lcdui.*;
public class
QuizMidlet extends MIDlet implements CommandListener
{
private Display display;
private Form
form1,form2,form3,form4,form5;
privateChoiceGroup
ch1,ch2,ch3,ch4;
private Command
next,back,ok,exit;
privateStringItemst;
int count=0;
publicQuizMidlet()
{
display=Display.getDisplay(this);
next=new
Command("Next",Command.OK,1);
back=new
Command("Back",Command.BACK,1);
st=new
StringItem("Total correct answers","0");
form1=new
Form("1.J2ME is?");
ch1=new
ChoiceGroup("",Choice.EXCLUSIVE);
ch1.append("mobile
java", null);
ch1.append("java
automatic", null);
ch1.append("standard
java", null);
ch1.append("for
serverside", null);
form1.append(ch1);
form1.addCommand(next);
form1.setCommandListener(this);
form5=new
Form("Score");
exit=new
Command("Exit",Command.SCREEN,1);
ok=new
Command("Submit",Command.OK,2);
form5.addCommand(ok);
form5.addCommand(exit);
form5.setCommandListener(this);
}
public void
startApp()
{
display.setCurrent(form1);
}
public void
pauseApp()
{
}
public void
destroyApp(boolean unconditional)
{
}
public void
commandAction(Command cmd,Displayable displayable)
{
if(displayable==form1)
{
if(cmd==next)
display.setCurrent(form2);
}
else
if(displayable==form4)
{
if(cmd==next)
{
if(ch1.getSelectedIndex()==0)
count++;
if(ch2.getSelectedIndex()==3)
count++;
if(ch3.getSelectedIndex()==1)
count++;
if(ch4.getSelectedIndex()==1)
count++;
st.setText(String.valueOf(count));
form5.append(st);
display.setCurrent(form5);
}
else
if(cmd==back)
{
display.setCurrent(form3);
}
}
else
if(displayable==form5)
{
if(cmd==ok)
{
display.setCurrent(form1);
}
else
if(cmd==exit)
{
destroyApp(false);
notifyDestroyed();
}
}
}
}
OUTPUT:
EX.NO:06 STOPWATCH
AIM:
To develop a stopwatch
timer using J2ME.
package
stopwatch;
import
java.util.*;
import
javax.microedition.midlet.*;
import
javax.microedition.lcdui.*;
public
class Midlet extends MIDlet implements CommandListener
{
int i, mdetik, detik, menit, jam;
Display
layar;
Form
frm;
Timer
tm;
TextField
tf;
TimerWatch
task;
Command
start, pause, reset;
public
void startApp()
{
layar=Display.getDisplay(this);
frm=new
Form("Timer");
tf=new
TextField("Stop Watch","",50,TextField.ANY);
start=new
Command("Start",Command.OK,0);
pause=new
Command("pause",Command.OK,0);
reset=new
Command("reset",Command.OK,0);
frm.append(tf);
frm.addCommand(start);
tm=new
Timer();
frm.setCommandListener((CommandListener)this);
layar.setCurrent(frm);
}
public
void pauseApp()
{
}
public
void destroyApp(boolean unconditional)
{
}
public
void commandAction(Command c, Displayable d)
{
if(c==start)
{
frm.removeCommand(start);
frm.removeCommand(reset);
frm.addCommand(pause);
tm=new
Timer();
task=new
TimerWatch();
tm.schedule(task,
0, 100);
}
if(c==pause)
{
frm.removeCommand(pause);
frm.addCommand(start);
frm.addCommand(reset);
tm.cancel();
}
if(c==reset)
{
i=0;
mdetik=0;
detik=0;
menit=0;
jam=0;
frm.removeCommand(pause);
frm.addCommand(start);
tf.setString("0:0:0:0");
tm=new
Timer();
}
}
private
class TimerWatch extends TimerTask
{
public void run()
{
++mdetik;
if(mdetik>=9)
{
detik=detik+1;
mdetik=0;
}
if(detik>59)
{
menit=menit+1;
detik=0;
}
if(menit>59)
{
jam=jam+1;
menit=0;
}
tf.setString(jam+
":" +menit+ ":" +detik+ ":" +mdetik);
}
}
}
OUTPUT:
No comments:
Post a Comment