T Modul 13 J2ME

Post on 18-Nov-2014

518 views 1 download

Tags:

Transcript of T Modul 13 J2ME

J2ME GUI danInterkoneksi Client Server

Muhammad Zen S. Hadi, ST. MSc.

2

Contents

J2ME (Review)

GUI dalam J2ME (RadioButton dan CheckBox)

Passing parameter dgn radiobutton dan checkbox

Interkoneksi client server (PHP MySQL)

3

Arsitektur Jaringan dgn J2ME

4

Information Access and CommunicationBuying Movie Ticket

5

Klas Utama dalam paket lcduiTo be discussed in this lecture

6

Komponen ChoiceGroupMemberikan user pilihan dari list yang tersedia. Terdapat 3 format ChoiceGroup : EXCLUSIVE : satu pilihanMULTIPLE : banyak pilihanPOPUP : satu pilihan dengan tampilan popup

7

Komponen ChoiceGroupFormat:– ChoiceGroup(String label, int choiceType)

Membuat obyek ChoiceGroup dan menentukantitle dan tipenya.

– ChoiceGroup(String label, int choiceType, String[] stringElements, Image[] imageElements)Membuat obyek ChoiceGroup, menentukan title dan tipe serta array dari string dan gambar untuknilai awal.

Untuk passing parameter dari pilihan user gunakangetSelectedIndex(), getString(int elementNum) andisSelected(int elementNum).

8

Contoh TextFieldChoiceGroupTestForm Registrasi untuk memasukkan data pribadi danmenampilkannya di dalam console.

9

Untuk Satu Pilihan (EXCLUSIVE)

10

Untuk Satu Pilihan (POPUP)

11

Passing Parameter dgn RadioButton

12

Passing Parameter dgn RadioButton

13

Banyak Pilihan (MULTIPLE)

14

Passing Parameter dgn CheckBox

15

Aplikasi untuk CheckBox

Untuk fungsi pauseApp(), destroyApp(), awal(), keluar() sama dengan program sebelumnya

16

17

Menampilkan banyak project

18

INTERKONEKSI CLIENT SERVER

19

IntroductionJ2ME provides networking features to the mobile devices. It is possible to get up-to-the-minute stock quotes or updated currency exchange rates on a mobile phone.The javax.microedition.io classes and interfaces handle the networking capability of MIDP.The java.io package provides input/output (I/O) capability to MIDP.

20

J2ME Networking CategoriesJ2ME networking has 3 categories:– Low-level IP networking– HTTP networking– Secure networking

The most critical aspect of J2ME network connectivity is communication between a mobile device and Web server.

21

Low-level IP networkingThis category involves socket, datagram, serial port, and file I/O communication. Socket-based communication conforms to the connection-oriented TCP/IP protocol. Datagram-based communication conforms to the connectionless UDP/IP protocol. e.g. URI for a datagram connection for sending to a server on a certain port:– datagram://123.456.789.12:1234

Low-level IP networking can also handle file I/O and can allow a MIDlet to use a local serial port.

22

HTTP networkingThe communication between a mobile device and a Web server is based on HTTP (Hypertext Transfer Protocol). HTTP is a connection-oriented request-response protocol.

23

The Connection FrameworkJ2ME networking was designed to address the diverse needs of a wide range of mobile devices. At the same time, the networking system must be device specific. To meet these challenges, it introduces the concept of a generic connection framework.Generic connection framework is to define the general aspects of the networking and file I/O in the form of Java interfaces for a broad range of handheld devicesLeave the actual implementations of these interfaces to individual device manufacturers.

24

The Connection Framework

25

URL Handling in J2MEURL handling in J2ME involves opening a connection to the Web server from the mobile device and handling data I/O between the two. The process happens in the following stages:– Setup– Connected– Closed

J2ME defines the javax.microedition.io.Connectorclass to create all the connection objects. In URL handling, Connector.open() is used to open a URL; it returns an HttpConnection object.

26

URL Handling in J2METhe string parameter to the Connector.open() method is a valid URL. The URL string varies depending on the communication protocol, as Examples 1 through 5 below demonstrate.

Example 1. Invoking HTTP-based communicationConnection conn =

Connector.open("http://www.yahoo.com");

Example 2. Invoking stream-based socket communicationConnection conn =

Connector.open("socket://localhost:9000");

27

URL Handling in J2MEExample 3. Invoking datagram-based socket communicationConnection conn =

Connector.open("datagram://:9000");

Example 4. Invoking serial port communicationConnection conn =

Connector.open("comm:0;baudrate=9000");

Example 5. Invoking file I/O communicationConnection conn =

Connector.open("file://myfile.dat");

28

URL Handling in J2METhe Connector.open() method also accepts the access mode (values READ, WRITE, and READ_WRITE), and a flag to indicate that the caller wants a timeout notification. – static Connection open(String name, int mode)

– static Connection open(String name, int mode, boolean timeouts)

The method openInputStream() of Connector opens an input stream of bytes (java.io.InputStream).

29

URL Handling in J2MESimilarly, a java.io.OutputStream representing an output stream of bytes.The counterparts of InputStream and OutputStreamare java.io.DataInputStream and java.io.DataOutputStream, respectively. A DataInputStream/DataOutputStream lets an application read/write primitive Java data types.

30

Akses file text dari Server

server

Simpan file text dihttp://127.0.0.1/modu13/pesan1.txt

31

Menghilangkan tampilan AirTime

32

Aplikasi akses file text dari Server

33

Aplikasi akses file text dari Server

34

Akses file php dari Server

server

Simpan file php dihttp://127.0.0.1/modu13/lat1.php

35

Aplikasi akses file php dari ServerSemua bagian sama seperti program sebelumnya

36

Passing Parameters to ServerTypically, an HTTP request to a server is accompanied by information needed by the server to process the request.

37

Passing Parameters to Servere.g. Login in case. A server must authenticate a client using the client’s user ID and password. The client sends the user ID and password along with the HTTP request. Two techniques are used to send data to the server:GET or POST request methods.The GET request method requires that data be concatenated to the URL of the server. The POST request method requires that each pair value be written to the output stream.

38

Passing Parameters to ServerData sent to a server must be in a pair value set:

– field name– the value associated with the field.

The field name and value must be separated by an equal sign (=).The pair value sets are separated from the URL by a question mark (?). Each pair value set is separated from other pair value sets by an ampersand (&).The space character is converted to a plus (+) sign.For example, the following request sends two parameters: pOne="one bit" and pTwo="two"

http://127.0.0.1/modul13/simple.php?p=one+bit&pTwo=two

39

Akses file php dgn parameter

server

Simpan file php dihttp://127.0.0.1/modu13/lat2.php

40

Aplikasi Akses File php dgn parameter

41

Akses file php dgn parameter (2)

server

Simpan file php dihttp://127.0.0.1/modu13/lat3.php

42

Aplikasi Akses File php dgn parameter (2)

43

Interaksi dengan Database (Review)Dalam pembuatan aplikasi berbasis Database –WAP, beberapa perintah di Database baik DML danDDL bisa digunakan dikarenakan aksesnya masihberbasis PHP.Beberapa tahapan dalam interkoneksi denganDatabase :Membuka koneksi ke server MySQL

$conn = mysql_connect (”host”,”username”,”password”);

Memilih databasemysql_select_db(”namadatabase”,$conn);

Memilih tabel dengan query$hasil = mysql_query(”SQL Statement”);

Mengambil record dari tabel$row = mysql_fetch_row($hasil);

44

Contoh aplikasi berbasis J2ME - Database

Buat database KAMPUS, dengan tabel Mahasiswa yang memiliki field sebagai berikut, dengan NRP sebagaiPrimary Key :

Akan dibuat aplikasi untuk memasukkan data baru, danmenampilkan data dengan J2ME.

45

Input Data ke Database

server

Simpan file php dihttp://127.0.0.1/modu13/prosesInsert.php

46

Aplikasi Input Data ke Database

47

Aplikasi Input Data ke Database

48

Tampil Data dari Database

server

Simpan file php dihttp://127.0.0.1/modu13/prosesTampil.php

49

Aplikasi Tampil Data dari Database

50

Aplikasi Tampil Data dari Database

51

TUGASBuat aplikasi untuk menghitung biaya total pemakaian PDAM :a. Buat databasenya

Golongan Biaya (m3)1 5002 10003 1500

b. Input user :Nama user : Fakhri [TextField]Golongan : 1 [ChoiceGroup dgn 1 pilihan]Pemakaian : 20 [TextField]

c. Output :Nama : FakhriTotal yang harus dibayar : Rp. 10000

52

TUGASPresentasi tiap kelompok untuk proyeknya :a. Blok Diagram Sistemb. Sistem Database