t modul 13 j2me
TRANSCRIPT
![Page 1: T Modul 13 J2ME](https://reader030.vdocument.in/reader030/viewer/2022020306/5571fa2649795991699165c1/html5/thumbnails/1.jpg)
J2ME GUI danInterkoneksi Client Server
Muhammad Zen S. Hadi, ST. MSc.
![Page 2: T Modul 13 J2ME](https://reader030.vdocument.in/reader030/viewer/2022020306/5571fa2649795991699165c1/html5/thumbnails/2.jpg)
2
Contents
J2ME (Review)
GUI dalam J2ME (RadioButton dan CheckBox)
Passing parameter dgn radiobutton dan checkbox
Interkoneksi client server (PHP MySQL)
![Page 3: T Modul 13 J2ME](https://reader030.vdocument.in/reader030/viewer/2022020306/5571fa2649795991699165c1/html5/thumbnails/3.jpg)
3
Arsitektur Jaringan dgn J2ME
![Page 4: T Modul 13 J2ME](https://reader030.vdocument.in/reader030/viewer/2022020306/5571fa2649795991699165c1/html5/thumbnails/4.jpg)
4
Information Access and CommunicationBuying Movie Ticket
![Page 5: T Modul 13 J2ME](https://reader030.vdocument.in/reader030/viewer/2022020306/5571fa2649795991699165c1/html5/thumbnails/5.jpg)
5
Klas Utama dalam paket lcduiTo be discussed in this lecture
![Page 6: T Modul 13 J2ME](https://reader030.vdocument.in/reader030/viewer/2022020306/5571fa2649795991699165c1/html5/thumbnails/6.jpg)
6
Komponen ChoiceGroupMemberikan user pilihan dari list yang tersedia. Terdapat 3 format ChoiceGroup : EXCLUSIVE : satu pilihanMULTIPLE : banyak pilihanPOPUP : satu pilihan dengan tampilan popup
![Page 7: T Modul 13 J2ME](https://reader030.vdocument.in/reader030/viewer/2022020306/5571fa2649795991699165c1/html5/thumbnails/7.jpg)
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).
![Page 8: T Modul 13 J2ME](https://reader030.vdocument.in/reader030/viewer/2022020306/5571fa2649795991699165c1/html5/thumbnails/8.jpg)
8
Contoh TextFieldChoiceGroupTestForm Registrasi untuk memasukkan data pribadi danmenampilkannya di dalam console.
![Page 9: T Modul 13 J2ME](https://reader030.vdocument.in/reader030/viewer/2022020306/5571fa2649795991699165c1/html5/thumbnails/9.jpg)
9
Untuk Satu Pilihan (EXCLUSIVE)
![Page 10: T Modul 13 J2ME](https://reader030.vdocument.in/reader030/viewer/2022020306/5571fa2649795991699165c1/html5/thumbnails/10.jpg)
10
Untuk Satu Pilihan (POPUP)
![Page 11: T Modul 13 J2ME](https://reader030.vdocument.in/reader030/viewer/2022020306/5571fa2649795991699165c1/html5/thumbnails/11.jpg)
11
Passing Parameter dgn RadioButton
![Page 12: T Modul 13 J2ME](https://reader030.vdocument.in/reader030/viewer/2022020306/5571fa2649795991699165c1/html5/thumbnails/12.jpg)
12
Passing Parameter dgn RadioButton
![Page 13: T Modul 13 J2ME](https://reader030.vdocument.in/reader030/viewer/2022020306/5571fa2649795991699165c1/html5/thumbnails/13.jpg)
13
Banyak Pilihan (MULTIPLE)
![Page 14: T Modul 13 J2ME](https://reader030.vdocument.in/reader030/viewer/2022020306/5571fa2649795991699165c1/html5/thumbnails/14.jpg)
14
Passing Parameter dgn CheckBox
![Page 15: T Modul 13 J2ME](https://reader030.vdocument.in/reader030/viewer/2022020306/5571fa2649795991699165c1/html5/thumbnails/15.jpg)
15
Aplikasi untuk CheckBox
Untuk fungsi pauseApp(), destroyApp(), awal(), keluar() sama dengan program sebelumnya
![Page 16: T Modul 13 J2ME](https://reader030.vdocument.in/reader030/viewer/2022020306/5571fa2649795991699165c1/html5/thumbnails/16.jpg)
16
![Page 17: T Modul 13 J2ME](https://reader030.vdocument.in/reader030/viewer/2022020306/5571fa2649795991699165c1/html5/thumbnails/17.jpg)
17
Menampilkan banyak project
![Page 18: T Modul 13 J2ME](https://reader030.vdocument.in/reader030/viewer/2022020306/5571fa2649795991699165c1/html5/thumbnails/18.jpg)
18
INTERKONEKSI CLIENT SERVER
![Page 19: T Modul 13 J2ME](https://reader030.vdocument.in/reader030/viewer/2022020306/5571fa2649795991699165c1/html5/thumbnails/19.jpg)
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.
![Page 20: T Modul 13 J2ME](https://reader030.vdocument.in/reader030/viewer/2022020306/5571fa2649795991699165c1/html5/thumbnails/20.jpg)
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.
![Page 21: T Modul 13 J2ME](https://reader030.vdocument.in/reader030/viewer/2022020306/5571fa2649795991699165c1/html5/thumbnails/21.jpg)
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.
![Page 22: T Modul 13 J2ME](https://reader030.vdocument.in/reader030/viewer/2022020306/5571fa2649795991699165c1/html5/thumbnails/22.jpg)
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.
![Page 23: T Modul 13 J2ME](https://reader030.vdocument.in/reader030/viewer/2022020306/5571fa2649795991699165c1/html5/thumbnails/23.jpg)
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.
![Page 24: T Modul 13 J2ME](https://reader030.vdocument.in/reader030/viewer/2022020306/5571fa2649795991699165c1/html5/thumbnails/24.jpg)
24
The Connection Framework
![Page 25: T Modul 13 J2ME](https://reader030.vdocument.in/reader030/viewer/2022020306/5571fa2649795991699165c1/html5/thumbnails/25.jpg)
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.
![Page 26: T Modul 13 J2ME](https://reader030.vdocument.in/reader030/viewer/2022020306/5571fa2649795991699165c1/html5/thumbnails/26.jpg)
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");
![Page 27: T Modul 13 J2ME](https://reader030.vdocument.in/reader030/viewer/2022020306/5571fa2649795991699165c1/html5/thumbnails/27.jpg)
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");
![Page 28: T Modul 13 J2ME](https://reader030.vdocument.in/reader030/viewer/2022020306/5571fa2649795991699165c1/html5/thumbnails/28.jpg)
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).
![Page 29: T Modul 13 J2ME](https://reader030.vdocument.in/reader030/viewer/2022020306/5571fa2649795991699165c1/html5/thumbnails/29.jpg)
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.
![Page 30: T Modul 13 J2ME](https://reader030.vdocument.in/reader030/viewer/2022020306/5571fa2649795991699165c1/html5/thumbnails/30.jpg)
30
Akses file text dari Server
server
Simpan file text dihttp://127.0.0.1/modu13/pesan1.txt
![Page 31: T Modul 13 J2ME](https://reader030.vdocument.in/reader030/viewer/2022020306/5571fa2649795991699165c1/html5/thumbnails/31.jpg)
31
Menghilangkan tampilan AirTime
![Page 32: T Modul 13 J2ME](https://reader030.vdocument.in/reader030/viewer/2022020306/5571fa2649795991699165c1/html5/thumbnails/32.jpg)
32
Aplikasi akses file text dari Server
![Page 33: T Modul 13 J2ME](https://reader030.vdocument.in/reader030/viewer/2022020306/5571fa2649795991699165c1/html5/thumbnails/33.jpg)
33
Aplikasi akses file text dari Server
![Page 34: T Modul 13 J2ME](https://reader030.vdocument.in/reader030/viewer/2022020306/5571fa2649795991699165c1/html5/thumbnails/34.jpg)
34
Akses file php dari Server
server
Simpan file php dihttp://127.0.0.1/modu13/lat1.php
![Page 35: T Modul 13 J2ME](https://reader030.vdocument.in/reader030/viewer/2022020306/5571fa2649795991699165c1/html5/thumbnails/35.jpg)
35
Aplikasi akses file php dari ServerSemua bagian sama seperti program sebelumnya
![Page 36: T Modul 13 J2ME](https://reader030.vdocument.in/reader030/viewer/2022020306/5571fa2649795991699165c1/html5/thumbnails/36.jpg)
36
Passing Parameters to ServerTypically, an HTTP request to a server is accompanied by information needed by the server to process the request.
![Page 37: T Modul 13 J2ME](https://reader030.vdocument.in/reader030/viewer/2022020306/5571fa2649795991699165c1/html5/thumbnails/37.jpg)
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.
![Page 38: T Modul 13 J2ME](https://reader030.vdocument.in/reader030/viewer/2022020306/5571fa2649795991699165c1/html5/thumbnails/38.jpg)
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
![Page 39: T Modul 13 J2ME](https://reader030.vdocument.in/reader030/viewer/2022020306/5571fa2649795991699165c1/html5/thumbnails/39.jpg)
39
Akses file php dgn parameter
server
Simpan file php dihttp://127.0.0.1/modu13/lat2.php
![Page 40: T Modul 13 J2ME](https://reader030.vdocument.in/reader030/viewer/2022020306/5571fa2649795991699165c1/html5/thumbnails/40.jpg)
40
Aplikasi Akses File php dgn parameter
![Page 41: T Modul 13 J2ME](https://reader030.vdocument.in/reader030/viewer/2022020306/5571fa2649795991699165c1/html5/thumbnails/41.jpg)
41
Akses file php dgn parameter (2)
server
Simpan file php dihttp://127.0.0.1/modu13/lat3.php
![Page 42: T Modul 13 J2ME](https://reader030.vdocument.in/reader030/viewer/2022020306/5571fa2649795991699165c1/html5/thumbnails/42.jpg)
42
Aplikasi Akses File php dgn parameter (2)
![Page 43: T Modul 13 J2ME](https://reader030.vdocument.in/reader030/viewer/2022020306/5571fa2649795991699165c1/html5/thumbnails/43.jpg)
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);
![Page 44: T Modul 13 J2ME](https://reader030.vdocument.in/reader030/viewer/2022020306/5571fa2649795991699165c1/html5/thumbnails/44.jpg)
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.
![Page 45: T Modul 13 J2ME](https://reader030.vdocument.in/reader030/viewer/2022020306/5571fa2649795991699165c1/html5/thumbnails/45.jpg)
45
Input Data ke Database
server
Simpan file php dihttp://127.0.0.1/modu13/prosesInsert.php
![Page 46: T Modul 13 J2ME](https://reader030.vdocument.in/reader030/viewer/2022020306/5571fa2649795991699165c1/html5/thumbnails/46.jpg)
46
Aplikasi Input Data ke Database
![Page 47: T Modul 13 J2ME](https://reader030.vdocument.in/reader030/viewer/2022020306/5571fa2649795991699165c1/html5/thumbnails/47.jpg)
47
Aplikasi Input Data ke Database
![Page 48: T Modul 13 J2ME](https://reader030.vdocument.in/reader030/viewer/2022020306/5571fa2649795991699165c1/html5/thumbnails/48.jpg)
48
Tampil Data dari Database
server
Simpan file php dihttp://127.0.0.1/modu13/prosesTampil.php
![Page 49: T Modul 13 J2ME](https://reader030.vdocument.in/reader030/viewer/2022020306/5571fa2649795991699165c1/html5/thumbnails/49.jpg)
49
Aplikasi Tampil Data dari Database
![Page 50: T Modul 13 J2ME](https://reader030.vdocument.in/reader030/viewer/2022020306/5571fa2649795991699165c1/html5/thumbnails/50.jpg)
50
Aplikasi Tampil Data dari Database
![Page 51: T Modul 13 J2ME](https://reader030.vdocument.in/reader030/viewer/2022020306/5571fa2649795991699165c1/html5/thumbnails/51.jpg)
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
![Page 52: T Modul 13 J2ME](https://reader030.vdocument.in/reader030/viewer/2022020306/5571fa2649795991699165c1/html5/thumbnails/52.jpg)
52
TUGASPresentasi tiap kelompok untuk proyeknya :a. Blok Diagram Sistemb. Sistem Database