Sunteți pe pagina 1din 20

By

N.Malathy
AP/IT
Introduction
J2ME stands for Java 2, Micro Edition.
Stripped-down version of Java
Targeted at limited processing power & storage
capabilities ,low-bandwidth network connectivity
devices.
Example:
Mobile Phones,Pagers,PDA etc..
J2ME Stack
Configurations-Defines a minimum platform for a
horizontal category or grouping of devices with
similar requirements on memory and processing
power.
Two Types:
Connected Limited Device Configuration(CLDC)
Connected Device Configuration (CDC).



J2ME Stack(Contd..)
Profiles-a collection of Java APIs that supplement a
Configuration to provide capabilities for a specific
device group or market type
Mobile Information Device Profile (MIDP)
enhanced user interface, multimedia and game
functionality, end-to-end security





J2ME Stack(Contd..)
Foundation Profile
APIs that support resource-constrained devices
without a standards-based GUI system
Personal Profile
application environment for the high-end PDA
market .
Personal Basis Profile
network-connected devices

J2ME Stack(Contd..)
Optional Packages-set of APIs that support
additional and common behaviors
Examples of optional packages:
Bluetooth Optional Package
JDBC Optional Package
File connection
MIDLET
MIDP-set of APIs to handle mobile device specific issues
MIDP contains packages :
javax.microedition.lcdui
classes to enable developers to construct user interfaces
javax.microedition.io
Allows networking between midlets and other systems
javax.microedition.rms
Allows local storage
javax.microedition.midlet
Defines the midlet lifecycle

Life Cycle of a MIDlet

J2ME MIDP Development
Tools:
NetBeans IDE with Java ME Version 6.9 or later
Java Development Kit (JDK) Version 6 or 7
Sun Wireless Toolkit
Eclipse.
Creating a MIDP Application Using the Visual Mobile
Designer
Editing the Java Source Code
Compiling and Running the Project

Deploying MIDlets
MIDlets can be deployed on a phone in two ways:
Transfer the jar and jad files to the phone from the computer
via an external connection: serial cable, USB cable, IRDA,
Bluetooth
Over the Air (OTA) provisioning: download the midlet
suite from a server

/*Display Hello Message*/
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class Hello extends MIDlet {
private Form f;
public Hello()
{
f=new Form("Hello Midlet");
f.append("Hai Dude!!!");
}
public void startApp() {
Display.getDisplay(this).setCurrent(f); }
public void pauseApp() {}
public void destroyApp(boolean unconditional) {
}
}

Creating a User Interface
Textbox
TextField text =new TextField (text", , 32,TextField.ANY);
Command
Command c = new Command("OK", Command.OK, 0);
Types:
Command.OK Confirms a selection
Command.CANCEL Cancels pending changes
Command.BACK Moves the user back to a previous screen
Command.STOP Stop a running operation



Alert:
alert = new Alert("Failure", "Lost communication link!",
Img.png, ALERT_ERROR);
display.setCurrent(alert);
Form
private Form form;
private StringItem message;
form = new Form("My Form");
message = new StringItem("Welcome, ", "glad you could
come.");
form.append(message);

Radio/Checkbox:
Private ChoiceGroup radioButtons;
radioButtons = new ChoiceGroup("Select Your Color", Choice.EXCLUSIVE
/Multiple);
radioButtons.append("Red", null);
radioButtons.append("White", null);
radioButtons.append("Blue", null);
radioButtons.append("Green", null);
defaultIndex = radioButtons.append("All", null);
radioButtons.setSelectedIndex(defaultIndex, true);


/*Login*/
import javax.microedition.midlet.MIDlet;
import javax.microedition.lcdui.*;
public class LoginMidlet extends MIDlet implements CommandListener {
private Display display;
private TextField userName;
private TextField password;
private Form form;
private Command cancel;
private Command login;
public LoginMidlet() {
userName = new TextField("LoginID:", "", 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);
}

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("qm") && password.equals("j2")) {
menu();
} else {
tryAgain(); } }

public void menu() {
List services = new List("Choose one", Choice.EXCLUSIVE);
services.append("Check Mail", null);
services.append("Compose", null);
services.append("Addresses", null);
services.append("Options", null);
services.append("Sign Out", null);
display.setCurrent(services); }
public void tryAgain() {
Alert error = new Alert("Login Incorrect", "Please try again", null,
AlertType.ERROR);
error.setTimeout(Alert.FOREVER);
userName.setString("");
password.setString("");
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()); } }}


DEMO..
Exercise
Use Appropriate User Interfaces
Develop a currency converter Application to convert
dollar to indian rupee
Develop a Calculator to perform Arithmetic
operations







THANK YOU..

S-ar putea să vă placă și