Senin, 05 Mei 2014

INTRODUCTION TO J2ME




Arsitektur Jaringan dgn J2ME
Introduction to J2ME - 01

Java 2 Platform Micro Edition (J2ME)
Introduction to J2ME - 02
  • Java platform for small devices
  • A subset of J2SE
  • Released mid June 1999
  • Target devices:
    – Two-way pagers
    – Mobile phones, smart phones
    – PDAs (inc PocketPCs)
    – TVs, VCRs, CD players
  • Almost every mobile phone support J2ME
 J2ME Phones
Introduction to J2ME - 03
3 Java Platforms
Introduction to J2ME - 04
Introduction to J2ME - 05

J2ME Architecture
  • To increase the flexibility of design, the J2ME consists of two distinct layers: Configurations and Profiles 
  • Configuration
    – Defines the minimum Java technology for a broad range of devices with similar capabilities
  • Profile
    – Provides capabilities, on top of configuration, for a specific device type
J2ME Architecture
Two types of J2ME configurations P fil
1. Connected Device Configuration

2. Connected Limited Device Configuration


Introduction to J2ME - 06
CLDC vs CDC
CLDC
  • 160 Kbytes to 512 Kbytes of total memory available
  • 16-bit or 32-bit processor
  • Low power consumption and often operating with battery power
  • Connectivity with limited bandwidth.

CDC
  • 2Mbytes or more memory for Java platform
  • 32-bit processor
  • High bandwidth network connection, most often using TCP/IP

CLDC
Introduction to J2ME - 07

Mobile Information Device Profile (MIDP)
  • Is a set of APIs that allow developers to control mobile device-specific problems
  • – i.e. user interfaces, local storage and client application lifecycles etc.
  • MIDlets minimum requirements
  • – 96 x 54 pixels mono screen
  • – two-way wireless network
  • – input device (i.e. keypad)
  • – 128 KB for CLDC/MIDP class and another 32 KB for the KVM
  • Midlets are the most important and popular applications in the J2ME family.

MIDP
Introduction to J2ME - 08

Building J2ME Apps- Tool
We will use Sun Java Wireless Toolkit 2.x for CLDC (The newest version is 2.5.2 in Jan 2008)
which can be downloaded from http://java.sun.com/j2me/download.html

Introduction to J2ME - 09

J2ME Wireless Toolkit Demo
  • Launch the Wireless Toolkit:
    – Start > Programs > Sun Java(TM) Wireless Toolkit 2.5.2 for CLDC
Introduction to J2ME -10
  • WTK already includes a set of demo programs ready run
J2ME Wireless Toolkit Demo
  • Select menu item File > Open Project ...
  • Select UIDemo and click Open Project.
Introduction to J2ME -11
  • The projects can be used as the templates of your applications.

J2ME Wireless Toolkit Demo
  • Click the Build and then the Run buttons.
Introduction to J2ME -12

J2ME Wireless Toolkit Demo
  • The main menu screen is shown up. You can choose a program and select Launch to start the program.
Introduction to J2ME -13
MIDlet Programming
  • Any MIDP application must extends MIDlet
  • This is the MIDP equivalent of an applet, where starting/stopping is under the control of the
    environment
  • Like Java applets, MIDlets have an application life cycle while running on a mobile device.
MIDlet Transition States
  • Specifically, a MIDlet can be in one of three states as
    shown:
Introduction to J2ME -14

Midlet Skeleton
Introduction to J2ME -15
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class MyApp extends MIDlet {
public void startApp() {
// start up code
}
public void pauseApp() {
// we aren't showing any more
}
public void destroyApp(boolean unconditional) {
// clean up
}
}


Two Level API
  • There are two areas the API which you should be concerned with - the high and low-level API.
  • High-Level Provides input elements such as,
    – text fields, choices, and form
  • Low-level is for drawing on Canvases and capturing keyed events
  • All MIDlet applications need to import the necessary midlet and lcdui packages:
    – import javax.microedition.midlet.*;
    – import javax.microedition.lcdui.*;
Displaying Objects - 01
  • High-level Screens have a base class called Displayable.
  • To show something on a MIDP device, you need to obtain the device’s display
    – javax.microedition.lcdui.Display class.
  • This Display class is the one and only display manager for each active MIDlet and provides
    information about the device’s display capability.
  • Subclassed Displayable classes will fill the whole screen
Displaying Objects - 02
  • To show a Displable object you must use the setCurrent() method on the Display object.
     Form mainForm = new Form ("First Program ");
     Display display = Display.getDisplay(this);
     display.setCurrent (mainForm);

Note that Form is a Displayable subclass.
Introduction to J2ME -16
Major classes in the lcdui package
Introduction to J2ME -17

First Example - HelloWorld
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class HelloWorld extends MIDlet {
public HelloWorld() {
}
public void startApp() {
Form form = new Form( "First Program" );
form.append( "Hello World" );
Display.getDisplay(this).setCurrent( form );
}
public void pauseApp() {
}

public void destroyApp( boolean unconditional ) {
}
}


Building the MIDlet using Netbeans 6-01
  • Run the program Netbeans IDE 6.0, File>New Project
  • Create new Project, Project Name : FirstProgram
  • Categories : Mobility, Projects : MIDP Application
Introduction to J2ME -18
Building the MIDlet using Netbeans 6-02
  • Project Name : FirstProgram
  • Uncheck : Create Hello Midlet

Introduction to J2ME -19

Building the MIDlet using Netbeans 6-03
  • Device Configuration : CLDC-1.1
  • Device Profile : MIDP-2.1
  • Click : Finish
Introduction to J2ME -20

Building the MIDlet using Netbeans 6-04
  • File > File…New File
  • Categories : MIDP
  • File Types: MIDlet

Introduction to J2ME -21
Building the MIDlet using Netbeans 6-05
  • Class Name : HelloWorld
  • Click : Finish
Introduction to J2ME -22
Building the MIDlet using Netbeans 6-06
Introduction to J2ME -23
Building and Run the MIDlet
  • Click the Run buttons.
Introduction to J2ME -24
Add another line
  • To make newline use ‘\n’
Introduction to J2ME -25
 Show Image
  • It supports jpg, png image and save in ‘res’ folder.
    Attention about image size, it must be enough to be
    displayed in LCD HP.
  • Adding image, it needs 2 part i.e. :
    a. Add import : import java.io.*;
    b. Exception :
    try { }
    catch (IOException e) {}
Example
Introduction to J2ME -26
Aplikasi Ticker
  • To add running text application in the HP.
Introduction to J2ME -27
 Simple Debugging
Introduction to J2ME -28
 How to download in to the Hp-01

Introduction to J2ME -29
  • After click Run button, automatically it will create jar
    file in the folder dist.
  • Only jar file will be downloaded in to the HP
How to download in to the HP-02
Introduction to J2ME -30
It must be same with the Java supported in the HP.

HP Specification
Introduction to J2ME -31

Tidak ada komentar:

Posting Komentar