Escolar Documentos
Profissional Documentos
Cultura Documentos
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
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.
26
URL Handling in J2ME
Example 3. Invoking datagram-based socket
communication
Connection conn =
Connector.open("datagram://:9000");
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)
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
31
Aplikasi akses file text dari Server
32
Aplikasi akses file text dari Server
33
Akses file php dari Server
server
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
40
Akses file php dgn parameter (2)
server
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
44
Input Data ke Database
server
46
Aplikasi Input Data ke Database
47
Tampil Data dari Database
server
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