Vous êtes sur la page 1sur 15

APPLET

by: Puan Hidayat/jtmk/psmza 1


Definition
• Applet is java program that can
be embedded into HTML
pages.

• Java applets runs on the java


enables web browsers such as
mozilla and internet explorer.

by: Puan Hidayat/jtmk/psmza 2


Introduction to Applets
• Applet is designed to run remotely on the
client browser, so there are some restrictions
on it.
• Applet can't access system resources on the
local computer. Applets are used to make the
web site more dynamic and entertaining. 

by: Puan Hidayat/jtmk/psmza 3


Introduction to Applets
• Advantages of Applet:
- Applets are cross platform and can run on Windows, Mac OS
and Linux platform
- Applets can work all the version of Java Plugin
- Applets runs in a sandbox, so the user does not need to trust
the code, so it can work without security approval
- Applets are supported by most web browsers
- Applets are cached in most web browsers, so will be quick to
load when returning to a web page
- User can also have full access to the machine if user allows

by: Puan Hidayat/jtmk/psmza 4


Introduction to Applets
• Disadvantages of Java Applet:
- Java plug-in is required to run applet
- Java applet requires JVM so first time it takes
significant startup time
- If applet is not already cached in the machine, it will
be downloaded from internet and will take time
- Its difficult to desing and build good user interface
in applets compared to HTML technology

by: Puan Hidayat/jtmk/psmza 5


• Differencess between Java Applets and Java
Application
Java Application Java Applet

Runs using Java Interpreter Runs on any browser or use


Appletviewer
Execution begins with Execution does not begin
main() method with the main() method
System.out.println() to Used method drawString()
display output tp display output

by: Puan Hidayat/jtmk/psmza 6


Write and Compile simple Applet
• Open Notepad and type coding as below:-

import java.awt.*;

public class Aplet extends java.applet.Applet


{
}

by: Puan Hidayat/jtmk/psmza 7


• Build your own FOLDER, Example F5105

• And Save As – Aplet.java

• If u are using JDK, set path the folder.

• Example : set path=path;C:\jdk1.3.1\bin

by: Puan Hidayat/jtmk/psmza 8


• If there are NO ERRORS, COMPILE using javac command
• Example : javac Aplet.java

• If there are NO ERRORS, BUILD HTML file as below :

<html>
<body>
<applet code="Aplet.class" width=300 height=300>
</applet>
</body>
</html>

• and SAVE AS :- Aplet.html

by: Puan Hidayat/jtmk/psmza 9


• RUN using appletviewer command
• Example : appletviewer Aplet.html

• RUN using Internet Explorer

by: Puan Hidayat/jtmk/psmza 10


Basic Applets Method
• Initialization: The init() method is called the first
time the applet is loaded.

• Starting: The start() method is called each time an


applet is loaded or reloaded. A start follows
initialization and also takes place each time the
applet is restarted. A start happens when a Web user
comes back to the applet's page after leaving it; you
can also call start() directly.

by: Puan Hidayat/jtmk/psmza 11


• Stopping: The stop() method is called each
time an applet is stopped. A stop happens
automatically when a Web page containing
the applet is exited and also when the stop()
method is called directly in a program.

• Destruction: The destroy() method is called


the final time the applet is exited.

by: Puan Hidayat/jtmk/psmza 12


• Painting: The paint()method is called any time
the applet window must be repainted. This
occurs automatically at certain times, such as
when the applet window is covered up by
another window and then uncovered. It also
can be called by using a repaint() call when a
program needs a screen update to take place.

by: Puan Hidayat/jtmk/psmza 13


Applet Life Cycle

init() start()
Initialization Applet start
Applet

start() stop()

Applet destroy Applet stop


destroy()

by: Puan Hidayat/jtmk/psmza 14


Develop Applets Programme using
basic Applet Method
• import java.awt.*;
• import javax.swing.*;

• public class KitarApplet extends JApplet


• {
• private int kali;
• private int lukis;

• public void init()
• {
• System.out.println("init: Applet melakukan pengawalan");
• kali=0;
• lukis=0;
• }
• public void start()
• {
• kali++;
• System.out.println("start: Applet dimulakan untuk kali ke -"+kali);
• }
• public void stop()
• {
• System.out.println("stop: Applet berhenti untuk kali ke -"+kali);
• }

• public void paint( Graphics g)


• {
• lukis++;
• System.out.println("paint: Applet dilukiskan untuk kali ke -"+lukis);
• g.drawString("Ini kotak biru",0,15);
• g.setColor(Color.blue);
• g.fillRect(20,20,30,50);

• }
• public void destroy()
• {
• System.out.println("Destroy: Applet ditamatkan");
• }
• }

by: Puan Hidayat/jtmk/psmza 15

Vous aimerez peut-être aussi