Presentasi sedang didownload. Silahkan tunggu

Presentasi sedang didownload. Silahkan tunggu

APPLET By : DHANIS PUSPA M (26262).

Presentasi serupa


Presentasi berjudul: "APPLET By : DHANIS PUSPA M (26262)."— Transcript presentasi:

1 APPLET By : DHANIS PUSPA M (26262)

2 BAHASAN PENDAHULUAN BEDA APLIKASI DAN APPLET MEMBUAT APPLET
MEMASUKKAN APPLET KE HALAMAN WEB APPLET TAG JAVA ARCHIVE PASSING PARAMETERS TO APPLETS

3 APPLET - PENDAHULUAN Program Java yang berada pada halaman Web yang kompatibel terhadap Java Seperti program aplikasi, namun tidak standalone Program yang dapat bereaksi terhadap masukan dari user dan berubah secara dinamis

4 BEDA APLIKASI - APPLET Aplikasi standalone, bisa di-run dg Java interpreter (command line). Pada applet, Java interpreter di-built pada browser (java plug-in) dan run file class Java dari sana. Applet memiliki akses ke struktur yang disediakan browser, Applet memiliki beberapa restriksi untuk kepentingan sekuritas

5 MEMBUAT APPLET Buat subclass dari class Applet dengan inisialisasi sebagai berikut: Method-method penting pada eksekusi applet (init, start, stop, destroy) Contoh applet sederhana public class myClass extends java.applet.Applet { ... }

6 Life Cycle pada Applet Inisialisasi Muncul saat applet di-load
Starting Dipanggil setelah init & menjadi titik awal setelah applet dihentikan public void init() { ... } public void start() { ... }

7 Dipanggil saat browser meninggalkan dokumen HTML yang berisi applet
Stop Dipanggil saat browser meninggalkan dokumen HTML yang berisi applet Destroy Dipanggil jika applet perlu dihapus dari memori (otomatis saat browser shut down) public void stop() { ... } public void destroy() { ... }

8 Code – Applet “Hello Again”
1 : import java.awt.Graphics; 2 : import java.awt.Font; 3 : import java.awt.Color; 4 : 5 : public class HelloAgainApplet extends java.applet.Applet { 6 : 7 : Font f = new Font("TimesRoman", Font.BOLD, 36); 8 : 9 : public void paint(Graphics g) { 10 : g.setFont(f); 11 : g.setColor(Color.red); 12 : g.drawString("Hello again!", 5, 40); 13 : } 14 :}

9 Eksekusi Applet – Applet Viewer
Compile file source menjadi file class Buat file HTML. Terdapat tag HTML tertentu yang digunakan untuk menampilkan applet Browser akan menggunakan informasi yang dikandung tag tersebut untuk alokasi class file dan eksekusi applet Enter appletviewer HelloAgainApplet.html pada command line

10 Tampilan Applet

11 Halaman HTML Sederhana
2: <HEAD> 3: <TITLE>This page has an applet on it </TITLE> 4: </HEAD> 5: <BODY> 6: <P>My second Java applet says:<BR> 7: <APPLET CODE="HelloAgainApplet.class" WIDTH=200 HEIGHT=50> 8: alt="Your browser understands the APPLET tag but isn't running the applet, for some reason." Your browser is completely ignoring the <APPLET> tag! 9: </APPLET> 10: </BODY> 11: </HTML>

12 ATRIBUT HTML - APPLET Positioning
LEFT, RIGHT, BOTTOM, TOP, TEXTTOP, MIDDLE, ABSMIDDLE, BASELINE, ABSBOTTOM, VSPACE, HSPACE, ALIGN, WIDTH, HEIGHT Code CODE, CODEBASE, ARCHIVE, OBJECT, NAME Java-Challenged Viewer ALT (MENAMPILKAN PESAN ADANYA APPLET JAVA PADA SUATU HALAMAN WEB)

13 Applet – LEFT align

14 Option Alignment Applet

15 Vertical-Horizontal Space
VSPACE=50 HSPACE=10

16 TAG HTML - APPLET Text antara tag <APPLET> dan </APPLET> ditampilkan browser jika unable Java Sehingga untuk browser unable Java tidak hanya melihat blank page

17 Memasukkan Applet pada Web Page
Membuat halaman Web yang akan menampilkan applet dengan menggunakan bahasa HTML Load file HTML ke browser untuk menampilkan applet

18 Tampilan pada Browser

19 Aplikasi  Applet Buat halaman HTML untuk load applet code
Suplai subclass dari class JApplet (public) Hilangkan method main pada aplikasi Pindahkan kode inisialisasi dari frame window constructor ke method init applet Hilangkan panggilan ke setsize, show setTitle & setDefaultCloseOperation

20 Passing Parameters to Applets
Applet dapat menggunakan parameter pada file HTML HTML tag <PARAM>, dengan atribut NAME dan VALUE yang ingin di-define: Passing parameter ke applet terjadi saat applet di-load <APPLET CODE="MyApplet.class" WIDTH=100 HEIGHT=100> <PARAM NAME=font VALUE="TimesRoman"> <PARAM NAME=size VALUE="36"> A Java applet appears here.</APPLET>

21 The MoreHelloApplet class.
INSTANCE VARIABLE UNTUK NAME 1: import java.awt.Graphics; 2: import java.awt.Font; 3: import java.awt.Color; 4: 5: public class MoreHelloApplet extends java.applet.Applet { 6: 7: Font f = new Font("TimesRoman", Font.BOLD, 36); 8: String name; 9: 10: public void init() { 11: name = getParameter("name"); 12: if (name == null) 13: name = "Laura"; 14: 15: name = "Hello " + name + "!"; 16: } 17: 18: public void paint(Graphics g) { 19: g.setFont(f); 20: g.setColor(Color.red); 21: g.drawString(name, 5, 40); 22: } 23: } SET VALUE UNTUK NAME DENGAN METHOD INIT () The MoreHelloApplet class. MODIFY NAME UNTUK MEMPEROLEH STRING LENGKAP

22 HTML file untuk MoreHelloApplet applet.
2: <HEAD> 3: <TITLE>Hello!</TITLE> 4: </HEAD> 5: <BODY> 6: <P> 7: <APPLET CODE="MoreHelloApplet.class" WIDTH=200 HEIGHT=50> 8: <PARAM NAME=name VALUE="Bonzo"> 9: Hello to whoever you are! 10: </APPLET> 11: </BODY> 12: </HTML>

23 Tampilan MoreHelloApplet

24 Tampilan MoreHelloApplet (null version)

25 TERIMA KASIH

26 SEKURITAS Applet tidak bisa read atau write ke sistem file pembaca, menghapus file atau melihat program apa yang telah di-install di hard drive. Applet tidak bisa berhubungan dengan server jaringan mana pun kecuali yang telah menyimpan applet, untuk mencegah applet menyerang sistem lain dari sistem pembaca. Applets tidak bisa menjalankan programapa pun pada sistem pembaca. Applets tidak bisa me-load native program ke local platform, termasuk shared libraries.

27 Positioning Attributes
WHAT IT DOES LEFT Places the applet at the left margin of the page. Text that follows on the page goes in space to the right of the applet. RIGHT Places the applet at the right margin of the page. Text that follows on the page goes in space to the left of the applet. BOTTOM Places the bottom of the applet at the bottom of the text in the current line. TOP Places the top of the applet with the top of the current line. TEXTTOP Places the top of the applet with the top of the text in the current line. MIDDLE Places the middle of the applet with the baseline of the current line. ABSMIDDLE Places the middle of the applet with the middle of the current line. BASELINE Places the bottom of the applet with the baseline of the current line. ABSBOTTOM Places the bottom of the applet with the bottom of the current line. VSPACE, HSPACE These optional attributes specify the number of pixels above and below the applet (VSPACE) and on each side of the applet (HSPACE). ALIGN Specifies the alignment of the applet. WIDTH, HEIGHT Gives the width and height of the applet, measured in pixels.

28 Code Attributes ATTRIBUTE WHAT IT DOES CODE
Gives the name of the applet’s class file, which taken relative to the codebase or relative to the current page. CODEBASE This optional attribute tells the browser that your class files are found below the directory indicated in the CODEBASE attribute. ARCHIVE This optional attribute lists the Java archive file or files containing classes and other resources for the applet. OBJECT Useful for implementing a persistent browser that automatically reload its applets and has them return to the same state that they were in where the browser was closed. NAME Used to refer to the applet when scripting. Also essential when you want two applets on the same page to communicate with each other directly.


Download ppt "APPLET By : DHANIS PUSPA M (26262)."

Presentasi serupa


Iklan oleh Google