0% found this document useful (0 votes)
47 views13 pages

Applets in Java

This document discusses applets and compares them to applications. It contains the following key points: 1. Applets are small Java programs that can be run from web browsers or the Applet Viewer. They can be transported over the Internet and run on other computers. Applets can perform tasks like calculations, graphics, sound, user input, animation and games. 2. Applets differ from applications in that they do not use the main() method, cannot run independently, cannot access local files or communicate with other servers, and have some library restrictions. 3. The lifecycle of an applet involves initialization methods like init(), start(), paint(), stop(), and destroy() being called in a specific sequence
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
Download as pptx, pdf, or txt
0% found this document useful (0 votes)
47 views13 pages

Applets in Java

This document discusses applets and compares them to applications. It contains the following key points: 1. Applets are small Java programs that can be run from web browsers or the Applet Viewer. They can be transported over the Internet and run on other computers. Applets can perform tasks like calculations, graphics, sound, user input, animation and games. 2. Applets differ from applications in that they do not use the main() method, cannot run independently, cannot access local files or communicate with other servers, and have some library restrictions. 3. The lifecycle of an applet involves initialization methods like init(), start(), paint(), stop(), and destroy() being called in a specific sequence
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1/ 13

APPLETS

• Applets are small Java programs that are primarily used in Internet
computing.
• They can be transported over the Internet from one computer to another
and run using the Applet Viewer or any Web browser that supports Java.
• An applet, like any application program, can do many things for us. It can
perform arithmetic operations, display graphics, play sounds, accept user
input, create animation, and play interactive games.
• Java has revolutionized the way the Internet users retrieve and use
documents on the world wide network.
• Java has enabled them to create and use fully interactive multimedia Web
documents.
Applet Vs Application

1. Applets do not use the main( ) method for initiating the execution of the code. Applets, when
loaded, automatically call certain methods of Applet class to start and execute the applet code.
2. Unlike stand-alone applications, applets cannot be run independently. They are run from inside a
Web page using a special feature known as HTML tag.
3. Applets cannot read from or write to the files in the local computer.
4. Applets cannot communicate with other servers on the network.
5. Applets cannot run any program from the local computer.
6. Applets are restricted from using libraries from other languages such as C or C++.
Running an Applet program

Before we try to write applets, we must make sure that Java is installed properly
and also ensure that either the Java appletviewer or a Java-enabled browser
is available. The steps involved in
developing and testing in applet are:
1. Building an applet code (.java file)
2. Creating an executable applet (.class file)
3. Designing a Web page using HTML tags
4. Preparing <APPLET> tag
5. Incorporating <APPLET> tag into the Web page
6. Creating HTML file
7. Testing the applet code
Applet Lifecycle
Applet Initialization and Termination
It is important to understand the order in which the various methods shown in the skeleton
are called. When an applet begins, the following methods are called, in this sequence:
1. init( )
2. start( )
3. paint( )
When an applet is terminated, the following sequence of method calls takes place:
1. stop( )
2. destroy( )
Let’s look more closely at these methods.
init( )
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.
start( )
The start( ) method is called after init( ). It is also called to restart an applet after it has beenstopped. Whereas init( ) is called
once—the first time an applet is loaded—start( ) is called each time an applet’s HTML document is dis played ons creen. So, if a
us er leaves a web page and comes back, the applet resumes execution at start( ).
paint( )
The paint( ) method is called each time your applet’s output mus t be redrawn. This situation can occur for several reasons
/* A simple applet that sets the foreground and
background colors and outputs a string. */
import java.awt.*;
import java.applet.*;
/*
<applet code="Sample" width=300 height=50>
</applet>
*/
public class Sample extends Applet{
String msg;
// set the foreground and background colors.
public void init() {
setBackground(Color.cyan);
setForeground(Color.red);
msg = "Inside init( ) --";
}
// Initialize the string to be displayed.
public void start() {
msg += " Inside start( ) --";
}
// Display msg in applet window.
public void paint(Graphics g) {
msg += " Inside paint( ).";
g.drawString(msg, 10, 30);
}
public void destroy() {
msg = "Inside init( ) --";
}
}
Circle & Ellipse

You might also like