Download presentation
Presentation is loading. Please wait.
1
APPLET PROGRAMMING IN JAVA
MRS.B.RAMA PRABHA, ASSISTANT PROFESSOR, DEPARTMENT OF COMPUTER SCIENCE, K.C.S.KASI NADAR COLLEGE OF ARTS & SCIENCE, CHENNAI-21
2
TOPICS COVERED INTRODUCTION. TYPES OF APPLET.
HOW APPLET IS DIFFER FROM OTHER APPLICATIONS. STEPS TO DEVELOP AN APPLET. APPLET LIFE CYCLE. HOW TO RUN AN APPLET.
3
INTRODUCTION An Applet is the special type of Java program that is run on web browser. An applet class does not have main method and it extends the java.applet.Applet class. An applet program runs through applet viewer. An applet is a special kind of Java program that is designed to be transmitted over the Internet and automatically executed by a Java-compatible web browser.
4
TYPES OF APPLET Applet Local applet Remote applet
5
HOW APPLET DIFFER FROM OTHER APPLICATIONS
Applets don’t use the main() method, but when they are loaded, automatically call certain methods (init, start, paint, stop, destroy). They are embedded inside a web page and executed in browsers. Takes input through Graphical User Input ( GUI ). They cannot read from or write to the files on local computer. They cannot run any programs from the local computer. They are restricted from using libraries from other languages.
6
STEPS TO DEVELOP AN APPLET
Building an applet code(.java file) Creating an executable file.(*.class file) Designing a web page using HTML tags. Preparing <APPLET> tag. Creating HTML file. Testing the applet code.
7
APPLET LIFE CYCLE When an applet is loaded it undergoes a series of changes in its states. The applet states include Born or Initialization state Running state Idle state Dead or destroyed state
8
APPLET LIFECYCLE INITIALIZATION RUNNING
The init( ) method is the first method to be called. This is where you should initialize variables. This method is called only once during the run time of your applet. RUNNING The start( ) method is called after init( ). It is also called to restart an applet after it has been stopped. It is called each time an applet’s HTML document is displayed on screen. So, if a user leaves a web page and comes back, the applet resumes execution at start( ).
9
Display paint() happens immediately after the applet enters into the running state.It is responsible for displaying output. paint( ) is also called when the applet begins execution. The paint( ) method is called each time your applet’s output must be redrawn. The paint( ) method has one parameter of type Graphics. Idle The stop( ) method is called when a web browser leaves the HTML document containing the applet—when it goes to another page. Dead/Destroyed State Applet is said to be dead when it is removed from memory. This occurs by calling destroy() method.
10
HOW TO RUN AN APPLET? There are two ways to run an applet
By html file. By applet Viewer tool .
11
Simple example of Applet by html file: To execute the applet by html file, create an applet and compile it. After that create an html file and place the applet code in html file. Now click the html file. <html> <body> <applet code="First.class" width="300" height="300"> </applet> </body> </html> //First.java import java.applet.Applet; import java.awt.Graphics; public class First extends Applet { public void paint(Graphics g) g.drawString(“Hello World",150,150); }
12
To execute the applet by applet viewer tool, write in command prompt:
To execute the applet by applet viewer tool, create an applet that contains applet tag in comment and compile it. After that run it by: applet viewer First.java. Now Html file is not required but it is for testing purpose only. //First.java import java.applet.Applet; import java.awt.Graphics; public class First extends Applet { public void paint(Graphics g){ g.drawString(“Hello world",150,150); } } /* <applet code="First.class" width="300" height="300"> </applet> */ To execute the applet by applet viewer tool, write in command prompt: c:\>javac First.java c:\>appletviewer First.java
13
OUTPUT
Similar presentations
© 2025 SlidePlayer.com Inc.
All rights reserved.