MODUL J2ME

Document Sample
MODUL J2ME Powered By Docstoc
					      J2ME GUI dan
Interkoneksi Client Server
 Muhammad Zen S. Hadi, ST. MSc.
Contents
 J2ME (Review)

 GUI dalam J2ME (RadioButton dan CheckBox)

 Passing parameter dgn radiobutton dan checkbox

 Interkoneksi client server (PHP MySQL)




                                                  2
Arsitektur Jaringan dgn J2ME




                               3
Information Access and Communication
 Buying Movie
 Ticket




                                   4
Klas Utama dalam paket lcdui
                       To be discussed in
                       this lecture




                                     5
Komponen ChoiceGroup
 Memberikan user pilihan dari list yang tersedia.
 Terdapat 3 format ChoiceGroup :
 EXCLUSIVE : satu pilihan
 MULTIPLE : banyak pilihan
 POPUP : satu pilihan dengan tampilan popup




                                                    6
Komponen ChoiceGroup
 Format:
 – ChoiceGroup(String label, int choiceType)
   Membuat obyek ChoiceGroup dan menentukan
   title dan tipenya.
 – ChoiceGroup(String label, int choiceType, String[]
   stringElements, Image[] imageElements)
   Membuat obyek ChoiceGroup, menentukan title
   dan tipe serta array dari string dan gambar untuk
   nilai awal.
 Untuk passing parameter dari pilihan user gunakan
 getSelectedIndex(), getString(int elementNum) and
 isSelected(int elementNum).


                                                   7
Contoh TextFieldChoiceGroupTest
 Form Registrasi untuk memasukkan data pribadi dan
 menampilkannya di dalam console.




                                                8
Untuk Satu Pilihan (EXCLUSIVE)




                                 9
Untuk Satu Pilihan (POPUP)




                             10
Passing Parameter dgn RadioButton




                                11
Passing Parameter dgn RadioButton




                                12
Banyak Pilihan (MULTIPLE)




                            13
Passing Parameter dgn CheckBox




                            14
Aplikasi untuk CheckBox




Untuk fungsi pauseApp(), destroyApp(), awal(), keluar()
sama dengan program sebelumnya                          15
16
Menampilkan banyak project




                             17
INTERKONEKSI
CLIENT SERVER




                18
Introduction
 J2ME 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.




                                                    19
J2ME Networking Categories
 J2ME 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.




                                                   20
Low-level IP networking
 This 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.



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




                                                  22
The Connection Framework
 J2ME 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
 devices
 Leave the actual implementations of these interfaces
 to individual device manufacturers.


                                                    23
The Connection Framework




                           24
URL Handling in J2ME
 URL 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.Connector
 class to create all the connection objects.
 In URL handling, Connector.open() is used to open a
 URL; it returns an HttpConnection object.


                                                    25
URL Handling in J2ME
 The 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 communication
 Connection conn =
    Connector.open("http://www.yahoo.com");
 Example 2. Invoking stream-based socket
 communication
 Connection conn =
    Connector.open("socket://localhost:9000");



                                                 26
URL Handling in J2ME
 Example 3. Invoking datagram-based socket
 communication
 Connection conn =
    Connector.open("datagram://:9000");

 Example 4. Invoking serial port communication
 Connection conn =
    Connector.open("comm:0;baudrate=9000");

 Example 5. Invoking file I/O communication
 Connection conn =
    Connector.open("file://myfile.dat");




                                                 27
URL Handling in J2ME
 The 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).




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




                                                     29
Akses file text dari Server




                           server




                Simpan file text di
                http://127.0.0.1/modu13/pesan1.txt
                                                 30
Menghilangkan tampilan AirTime




                                 31
Aplikasi akses file text dari Server




                                       32
Aplikasi akses file text dari Server




                                       33
Akses file php dari Server




                          server




               Simpan file php di
               http://127.0.0.1/modu13/lat1.php
                                                  34
Aplikasi akses file php dari Server
 Semua bagian sama seperti program sebelumnya




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




                                                 36
Passing Parameters to Server
 e.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.



                                                      37
Passing Parameters to Server
 Data 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
                                                 38
Akses file php dgn parameter




                     server




               Simpan file php di
               http://127.0.0.1/modu13/lat2.php
                                                  39
Aplikasi Akses File php dgn parameter




                                        40
Akses file php dgn parameter (2)




                     server




               Simpan file php di
               http://127.0.0.1/modu13/lat3.php
                                                  41
Aplikasi Akses File php dgn parameter (2)




                                        42
Interaksi dengan Database (Review)
Dalam pembuatan aplikasi berbasis Database –
WAP, beberapa perintah di Database baik DML dan
DDL bisa digunakan dikarenakan aksesnya masih
berbasis PHP.
Beberapa tahapan dalam interkoneksi dengan
Database :
Membuka koneksi ke server MySQL
 $conn = mysql_connect (”host”,”username”,”password”);
Memilih database
  mysql_select_db(”namadatabase”,$conn);
Memilih tabel dengan query
  $hasil = mysql_query(”SQL Statement”);
Mengambil record dari tabel
 $row = mysql_fetch_row($hasil);
                                                         43
 Contoh aplikasi berbasis J2ME - Database

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




Akan dibuat aplikasi untuk memasukkan data baru, dan
menampilkan data dengan J2ME.




                                                       44
Input Data ke Database



           server




              Simpan file php di
              http://127.0.0.1/modu13/prosesInsert.php
                                                   45
Aplikasi Input Data ke Database




                                  46
Aplikasi Input Data ke Database




                                  47
Tampil Data dari Database



           server




              Simpan file php di
              http://127.0.0.1/modu13/prosesTampil.php
                                                  48
Aplikasi Tampil Data dari Database




                                     49
Aplikasi Tampil Data dari Database




                                     50
TUGAS
 Buat aplikasi untuk menghitung biaya total
 pemakaian PDAM :
 a. Buat databasenya
      Golongan     Biaya (m3)
      1            500
      2            1000
      3            1500
 b. Input user :
      Nama user : Fakhri [TextField]
      Golongan : 1 [ChoiceGroup dgn 1 pilihan]
      Pemakaian : 20 [TextField]
 c. Output :
      Nama : Fakhri
      Total yang harus dibayar : Rp. 10000
                                                 51
TUGAS
 Presentasi tiap kelompok untuk proyeknya :
 a. Blok Diagram Sistem
 b. Sistem Database




                                              52

				
DOCUMENT INFO
Shared By:
Tags:
Stats:
views:320
posted:7/13/2011
language:Indonesian
pages:52