Java 2 Micro Edition Разработване на приложения за мобилни телефони Пламен Желязов Eternity Logic.

Slides:



Advertisements
Similar presentations
MIDP Mobile Information Device Profile Johnny Yau CIS 642 Prof. Insup Lee.
Advertisements

J2ME Form Nesneleri Melih Sakarya. Form Nesnesi Form form= new Form("Giris"); display.setCurrent(form);
J2ME Melih Sakarya Java Teknolojileri Derneği. JVM JAVA Kullanılan yerler  Windows-Linux-Unix-Solaris  PDA lar  Smart Cardlar  Cep Telefonları  Appletler.
Java 2D Training. Basic Tools Java SDK 1.4x Wireless Toolkit 2.x NetBeans IDE + mobility pack Global Code editor Text Comparer Tools Graphics Editor Sprite.
BA1 MIDP GUI BA2 Displayable hierarki Displayable ScreenCanvas TextBoxAlertFormList GameCanvas.
MIDP GUI Displayable hierarki Displayable ScreenCanvas TextBoxAlertFormList GameCanvas JEM1/jrt.
Department of Computer Science & Engineering
J2ME Screen Hierarchy Displayable ScreenCanvas FormAlertListTextbox.
Pengantar Teknologi Mobile 12
Writing Your First MIDlet Running JAVA on a Cell Phone Jon A. Batcheller January 27, 2004.
UNDERSTANDING JAVA APIS FOR MOBILE DEVICES v0.01.
Introduction to Java 2 Micro Edition Mark Balbes, Ph.D. Senior Software Engineer Jeff Brown Senior Software Engineer.
Java ME: CLDC и MIDP Борис Кварцхава
| 2004 JavaOne SM Conference | BOF JAVAONE 2004 Joe Bowbeer Software Designer UIEvolution, Inc. Cris Cook Graphic Designer UIEvolution, Inc.
Developing an Application with J2ME Technology Scott Palmer, Nat Panchee, Judy Sullivan, Karen Thabet, Sten Westgard.
J2ME RMI 1 Java 2 Platform, Micro Edition Implementation of J2ME RMI Application Farooq Sheikh.
J2ME for Palm Speaker: Chen-Nien Tsai Adviser: Kai-Wei Ke.
Introduction to Mobility Java Technology Mobile and Wireless Networks.
Developing Software for Wireless Devices
PDA Programming Using J2ME Presenter :涂俊凱 Date : 2003/4/8.
Making Cell Phone Games An Overview Ray Ratelis Guild Software, Inc.
Developing J2ME Applications Mobile and Wireless Networks.
The 21th century Repairman Agenda Introduction J2EE J2ME Demonstration.
Cosc 4730 Phone Programming in Java An Introduction.
Java 2 Micro Edition Mano Chen Senior Technical Consultant
Java Platform, Micro Edition (J2ME)
Java 2 Platform, Micro Edition (J2ME) By Xiaorong Wang.
Detecting Changes  ItemStateListener interface – detect changes in internal state of an Item  new selection made in a ChoiceGroup  adjusted value of.
J2ME and WAP Technologies CSCI – Independent Study Fall 2002 Presented by: Kashif Syed.
J2ME -Kushal Modi(09BIT056).
J2ME Java for Mobile Environments Based on J2ME In A Nutshell, by Kim Topley, O’Reilly & Associates Inc., 2002, and Tetris by Alexei Patinov.
Programming Handheld and Mobile devices 1 Programming of Handheld and Mobile Devices Lecture 12 Using the KToolbar Rob Pooley
Platforms and tools for Web Services and Mobile Applications J2ME based Applications Bent Thomsen Aalborg University 3rd and 4th of June 2004.
1 Mobile Software Development Framework 4/14/2009 Richard Yang.
Developed as a partial fulfillment of the requirements of ID2216 Sumanta Saha Md Sakhawat Hossen Md Safiqul Islam sumanta, hossen, BlueTTT.
Getting Started with JXTA for J2ME Advisor : Dr. Ching-Long Yeh Report : DI.2, 洪泰昌 ( ) Course: XML 文件管理.
Michael Brockway Advanced Applications Development in Java J2ME -- Introduction l Introduction / Overview l Java 2 Micro Edition n CLDC n MIDP l Examples.
Programming Handheld and Mobile devices 1 Programming of Handheld and Mobile Devices Lecture 11 J2ME and MIDlets Rob Pooley
Using J2ME to create Field Force Applications Chris Clark, MobileHWY, LLC.
Mobile Applications with Java ME & BlackBerry. Overview Java ME –Networking –Databases Java ME and the BlackBerry –The BlackBerry wireless device –Converting.
2013 Copyright © 2013 DAVID Holding Company Курс по информационни технологии Занятие №3 ADO.NET. LINQ to SQL.
Introduction to J2ME Shahryar Khan. Agenda J2ME Architecture Configurations and Profiles HelloWorld Application User Interface and Event Handling UI Examples.
Mobile Applications and Java ME
Framework and application bytecode size CLDC MIDP kXML parser Utility classes Graphics Logic (MIDlet) Application Data (XML file)
J2ME Presented by May Sayed & Menna Hawash. Outline Introduction “Java Technology” Introduction “What is J2ME?” J2ME Architecture J2ME Core Concepts 
1Basics of J2ME. 2 Objectives –Understand the different java API’s and how the mobile edition API’s fit in –Understand what a mobile configuration and.
Programming Handheld and Mobile devices 1 Programming of Handheld and Mobile Devices Lecture 12 lcdui Rob Pooley
Programming Handheld and Mobile devices 1 Programming of Handheld and Mobile Devices Lecture 13 lcdui and OXO Rob Pooley
Programming Handheld and Mobile devices 1 Programming of Handheld and Mobile Devices Lecture 14 Various MIDlet examples Rob Pooley
8-January-2003cse ProjectOverview © 2003 University of Washington1 Project Overview CSE 403, Winter 2003 Software Engineering
Wireless Java Possibilities, Services, Limitations, and Competitors.Wireless Java.
T Network Application Frameworks and XML Mobile Middleware Sasu Tarkoma.
Java 2 Platform, Micro Edition (J2ME)
1 Introduction to J2ME Outline MIDP Building J2ME Apps- Tool J2ME Wireless Toolkit Demo MIDlet Programming -- MIDlet Transition States -- Midlet Skeleton.
Lab 2: J2ME: Java 2 Micro Edition (Writing Programs for Mobile Phones using Java) Luis F. G. Sarmenta draft 3/13/2008 MIT D-Lab ICT4D.
CSE403: MIDlets and Ant1 MIDlets and Ant April 3, 2003 Shane Cantrell Zach Crisman.
Advance Computer Programming Market for Java ME The Java ME Platform – Java 2 Micro Edition (J2ME) combines a resource- constrained JVM and a set of Java.
Visual Mobile Applications with Netbeans 6.0 Your Name Sun Campus Ambassador Your Address.
Thái Duy Quý - Khoa CNTT-Đại học Đà Lạt
Digital Wireless Transmissions
Java N Amanquah.
Java N Amanquah.
By Jeff Heaton An Overview of J2ME By Jeff Heaton
J2ME User Interface I.
Shane Cantrell Zach Crisman
КОМПЮТЪР = АПАРАТУРА + ПРОГРАМНО ОСИГУРЯВАНЕ
Образци за възлагане на обществени поръчки в сила от / 01
Изход от конзолата.
Java for Mobile Devices
Presentation transcript:

Java 2 Micro Edition Разработване на приложения за мобилни телефони Пламен Желязов Eternity Logic

За какво ще говорим? ● Какво е Java ● Какво e CLDC и MIDP ● Преглед на достъпни API ● Какво е Мидлет ● LCDUI – Класове и възможности ● Други важни класове ● Примерна програма

Какво е Java? ● Езикът Java ● Java editions – Standard Edition (J2SE) – Enterprise Edition (J2EE) – Micro Edition (J2ME) ● Java Community Process (JCP) – JSR – Java Specification Request

Структура на J2ME ● CDC – Connected Device Configuration ● CLDC – Connected Limited Device Configuration ● Java Card Technology

CLDC Technology (1/3) ● Connected Limited Device Configuration (CLDC); JSR 30, JSR 139 ● Mobile Information Device Profile (MIDP); JSR 37, JSR 118 ● Information Module Profile, (IMP); JSR 195

CLDC Technology (2/3) ● Java Technology for the Wireless Industry, (JTWI); JSR 185 ● Mobile Media API (MMAPI); JSR 135 ● File Connection and PIM API (JSR 75) ● Location API for J2ME; JSR 179 ● SIP API for J2ME; JSR 180

CLDC Technology (3/3) ● Security and Trust Services API for J2ME (SATA); JSR-177 ● Mobile 3D Graphics; JSR-184 ● J2ME Web Services APIs (WSA), JSR-172 ● Bluetooth API JSR-82 ● J2ME Content Handler API (CHAPI) JSR 211

CLDC Версии ● CLDC 1.0 (JSR 30) – java.lang – java.util – java.io – javax.microedition.io ● CLDC 1.1 (JSR 139) – floating point операции – Поддръжка на weak reference – Подобрения в нишките

MIDP 1.0 ● MIDP 1.0 (JSR 37) – javax.microedition.lcdui – javax.microedition.lcdui.game – javax.microedition.media – javax.microedition.midlet – javax.microedition.rms

MIDP 2.0 ● MIDP 2.0 (JSR 118) – Enhanced user interface – Enhanced multimedia/gaming – Better connectivity (unbound connections) – OTA (over the air) provisioning – Better security

Видове устройства ● MIDP 1.0 / CLDC 1.0 – Nokia, Motorola, Siemens, LG, SE и други. ● MIDP 2.0 / CLDC 1.0 – Новите устройства на Nokia ser. 40, Nokia ser. 60, Siemens 65x, Motorola, SE, и други. ● MIDP 2.0 / CLDC 1.1 – Нови устройства от Nokia ser. 60, ser. 80, ser. 90, Siemens 65x, 75x, SE и други.

Optional Packages (1/2) ● Mobile Media API (MMAPI); JSR 135 ● Mobile 3D Graphics; JSR-184 ● J2ME Web Services APIs, (WSA); JSR 172 ● Bluetooth API (JSR-82) ● Location API for J2ME; JSR 179

Optional Packages (2/2) ● SIP API for J2ME; JSR 180 ● Security and Trust Services (SATSA); JSR-177 ● File Connection and PIM API (JSR 75)

API fragmentation Проблемът: Твърде много възможни комбинации: ● Различни размери на екрана и брой цветове ● Различни медийни формати ● Connectivity features (sms/ssl/udp) ● Vendor specific API (Nokia, Siemens и др.)

Решение? ● Разработка на отделни версии на критичните сегменти код ● Използване на “условна компилация” (j2mepolish, jpp и други). ● Когато е възможно – използване на най- ниска версия на API.

Java Technology for Wireless Industry: ● Стандартизация на минимален набор от API с цел избягване на фрагментацията: CLDC 1.0 (JSR 30) или CLDC 1.1 (JRS 139) MIDP 2.0 (JSR 118), WMA 1.1 (JSR 120), MMAPI (JSR 135) Поддържа се от най-новите устройства на всички големи производители. JTWI (JSR 185)

Какво е Midlet Suite Приложение, написано според MIDP спецификацията :) ● Съдържа един или повече наследници на javax.microedition.midlet.MIDlet ● class файловете са преминали процес на верификация ● Class-файловете са пакетирани в JAR ● JAD файл с допълнителна информация

Жизнен цикъл на Midlet

Как изглежда кода? import javax.microedition.midlet.MIDlet; import javax.microedition.midlet.MIDletStateChangeException; public class HelloWorldMidlet extends MIDlet { public HelloWorldMidlet() { super(); } protected void startApp() throws MIDletStateChangeException { } protected void pauseApp() { } protected void destroyApp(boolean arg0) throws MIDletStateChangeException { }

JAD Java Application Descriptor Съдържа информация за Midlet Suite ● Списък с мидлетите ● Версия на CLDC и MIDP ● Производител ● Адрес за инсталация ● Размер на JAR файла

Примерен JAD файл (1/2) MIDlet-1: Hello World,/icon1.png,HelloWorldMidlet MIDlet-2: Hello World Canvas,/icon2.png,HelloWorldCanvas MIDlet-Name: Lecture Midlet Suite MIDlet-Description: This is just Demo MIDlet-Jar-URL: MIDlet-Jar-Size: 5247 MIDlet-Data-Size: 1024 MIDlet-Version: MIDlet-Vendor: Eternity Logic MicroEdition-Profile: MIDP-1.0 MicroEdition-Configuration: CLDC-1.0

Примерен JAD файл (2/2) MIDlet-Info-URL: MIDlet-Install-Notify: logic.com/midlet_install.jsp?name=HelloWorld MIDlet-Delete-Notify: logic.com/midlet_uninstall.jsp?name=HelloWorld MIDlet-Delete-Confirm: Are you shure? MIDlet-Permissions: javax.microedition.io.Connector.http Property1: Value1 Property2: Value2

Преглед на LCDUI ➔ java.lang.Object ➔ Displayable ➔ Display ➔ AlertType ➔ Command ➔ Font ➔ Graphics ➔ Image ➔ Item ➔ Ticker ➔ Displayable ➔ Canvas ➔ Screen ➔ Form ➔ List ➔ TextBox ➔ Alert ➔ Item ➔ ChoiceGroup ➔ CustomItem ➔ DateField ➔ Gauge ➔ ImageItem ➔ Spacer ➔ StringItem ➔ TextField javax.microedition.lcdui classes ➔ Choice ChoiceGroup, List ➔ CommandListener ➔ ItemCommandListener ➔ ItemStateListener Interfaces

Hello World ! public class HelloWorldMidlet extends MIDlet implements CommandListener { Form helloForm = new Form ("Demo"); Command cmdExit = new Command ("Exit",Command.EXIT,0); protected void startApp() throws MIDletStateChangeException { helloForm.append("Hello World!"); helloForm.addCommand(cmdExit); helloForm.setCommandListener(this); Display.getDisplay(this).setCurrent(helloForm); } public void commandAction(Command cmd, Displayable displ) { if (displ==helloForm && cmd==cmdExit) { Display.getDisplay(this).setCurrent(null); notifyDestroyed(); }

Класът StringItem mainForm.append("This is a simple label"); item = new StringItem("This is a StringItem label: ", "This is the StringItems text"); mainForm.append(item); item = new StringItem("Short label: ", "text"); mainForm.append(item); item = new StringItem("Hyper-Link ", "hyperlink", Item.HYPERLINK); mainForm.append(item); item = new StringItem("Button ", "Button", Item.BUTTON); mainForm.append(item);

Класът Item Базов клас за всички класове, чиито инстанции могат да се добавят във форма По важни методи: ● getMinimumHeight(), getMinimumWidth(), getPreferredHeight(), getPreferredWidth(),setPreferredSize() ● notifyStateChanged() ● AddCommand (), removeCommand (), setDefaultCommand (), setItemCommandListener ● notifyStateChanged()

Класът Form Контейнер за Item subclasses. Методи: ● append(Image img), append(Item item), append(String str), set(int itemNum, Item item) ● delete(int itemNum), deleteAll() ● Item get(int itemNum) ● getHeight(), getWidth() ● setItemStateListener(ItemStateListener iListener)

The Layout (1/3) ● Не може да се разположи Item на конкретни координати. ● Елементите се показват по техния ред, в зависимост от имплементацията ● Елементите се разползагат в “Редове” ● Покзаването може да се управлява чрез метода setLayout () на класа Item ● Алгоритъмът за разползагане разчита на т.нар. Current Layout

The Layout (2/3) ● LAYOUT_DEFAULT ● LAYOUT_LEFT ● LAYOUT_RIGHT ● LAYOUT_CENTER ● LAYOUT_TOP ● LAYOUT_BOTTOM ● LAYOUT_VCENTER ● LAYOUT_NEWLINE_BEFORE ● LAYOUT_NEWLINE_AFTER ● LAYOUT_SHRINK ● LAYOUT_VSHRINK ● LAYOUT_EXPAND ● LAYOUT_VEXPAND ● LAYOUT_2

Класът TextField Constructor: TextField(String label, String text, int maxSize, int constraints) Sample: new TextField("Any Character", "", 15, TextField.ANY); new TextField(" ", "", 15, TextField. ADDR); new TextField("Number", "", 15, TextField.NUMERIC); new TextField("Decimal", "", 15, TextField.DECIMAL); new TextField("Phone", "", 15,TextField.PHONENUMBER); new TextField("Password", "", 15, TextField.PASSWORD); new TextField("URL", "", 15, TextField.URL);

Класът ChoiceGroup (1/2) String[] sa = {"Option A", "Option B", "Option C", "Option D"}; Image img = Image.createImage (“/pic.img”); form.append(new ChoiceGroup( "Exclusive", ChoiceGroup.EXCLUSIVE, sa, img)); form.append(new ChoiceGroup( "Multiple", ChoiceGroup.MULTIPLE, sa,img)); form.append(new ChoiceGroup( "Pop-Up", ChoiceGroup.POPUP, sa,img));

Класът Canvas – директен достъп до екрана ● Наследниците на Canvas имплементи-рат метод protected void paint(Graphics g) ● paint () не се вика директно – извиква се repaint () ● За директен достъп до екрана се използва параметъра (Graphics g)

Canvased Hello World! protected void paint(Graphics g) { g.drawLine(5,5,30,30); g.drawString("Hello World!", getWidth()/2, getHeight()/2, Graphics.TOP | Graphics.HCENTER); }

CustomItem Създаване на собствени контроли ● За създаване на собствени контроли се наследява класа javax.microedition.lcdui.CustomItem ● Задължително се имплементира void paint(Graphics g, int w, int h); ● Незадължително – traverse, traverseOut, keyPressed, keyReleased, keyRepeated и други.

Други UI класове (Screen) ● List – Аналог на ChoiceGroup, но се показва на цял екран ● Alert – Показва съобщение на екрана (info, warning, error и др.) ● TextBox – Аналог на TextField и също се показва на цял екран

Други интересни възможности (RMS) ● RMS – Record Memory Store – javax.microedition.rms.RecordStore – Позволява записване на информация върху мобилното устройство – Представлява номерирано множество от записи byte [] – Всеки запис се чете или записва наведнъж – Записите могат да се филтрират, търсят и сравняват по дадени признаци

Вход/Изход ● Пакетът javax.microedition.io – javax.microedition.io.Connector – factory за създаване на Connection обекти – Connection – Базов интерфейс за вход/изход – Поддържат се HttpConnection, HttpsConnection, SocketConnection, StreamConnection, UDPDatagramConnection

Пример за HTTP Вход HttpConnection httpcon = (HttpConnection) Connector.open(“ InputStream is = httpcon.openInputStream(); byte [] buff = new byte[128]; int count = -1; while ((count = is.read(buff))!=-1) { String text = new String (buff,count); form.append(text); }

Демонстрация: Да направим един Midlet ● Weather Midlet – показва метеороло- гичните условия в даден град ● Използваме web service предоставен от ● Ще направим заявка, ще изтеглим, обработим и визуализираме резултата

Формат на заявката и данните HTTP Get Request: webservicex.net/globalweather.asmx/GetWeather? CountryName=Bulgaria&CityName=Sofia

Формат на отговора Response: Sofia Observ., Bulgaria (LBSF) 42-39N E 595M Nov 29, :00 AM EST / UTC Variable at 2 MPH (2 KT) 4 mile(s) mostly clear 48 F (9 C) 41 F (5 C) 75% in. Hg (1015 hPa) Success

Да напишем кода ● Ще използваме Eclipse ● Плъгинът EclipseME ще автоматизира част от работата ● За емулатор – WTK 2.2 на Sun Microsystems

That’s all folks! Благодаря Ви за вниманието! Имате ли въпроси?