0% found this document useful (0 votes)
9 views

2024 10 12 Java Applet

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

2024 10 12 Java Applet

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Date : 12/Oct/2024 Afternoon Session

Applet in Java
Applet is a special type of program that is embedded in the webpage to generate the
dynamic content.
It runs inside the browser and works at client side.

Advantage of Applet
There are many advantages of applet. They are as follows:

• It works at client side so less response time.


• Secured
• It can be executed by browsers running under many plateforms, including Linux,
Windows, Mac Os etc.

Drawback of Applet

• Plugin is required at client browser to execute applet.

Hierarchy of Applet
Lifecycle of Java Applet

1. Applet is initialized.
2. Applet is started.
3. Applet is painted.
4. Applet is stopped.
5. Applet is destroyed.

java.applet.Applet class
For creating any applet java.applet.Applet class must be inherited. It provides 4 life cycle
methods of applet.

1. public void init(): is used to initialized the Applet. It is invoked only once.
2. public void start(): is invoked after the init() method or browser is maximized. It is
used to start the Applet.
3. public void stop(): is used to stop the Applet. It is invoked when Applet is stop or
browser is minimized.
4. public void destroy(): is used to destroy the Applet. It is invoked only once.
java.awt.Component class
The Component class provides 1 life cycle method of applet.

1. public void paint(Graphics g): is used to paint the Applet. It provides Graphics class
object that can be used for drawing oval, rectangle, arc etc.

Simple Example

F:\Advanced Java Training Aug2023\Programs\2023-10-11\AppletExample1.java


1 /*
2 Program : Applet Program 1
3 Date : 11 / OCt / 2023
4 Author ShriSoft
5
6 */
7
8 import java.awt.Graphics;
9 import java.applet.Applet;
10
11 public class AppletExample1 extends Applet
12 {
13
14 public void paint(Graphics g)
15 {
16 g.drawString("Welcome to YCP", 100, 100);
17 g.drawRect(200, 200, 150, 80);
18 }
19 }
20
21 /*
22 <applet code="AppletExample1.class" width="500" height="500" >
23 </applet>
24
25 */
How to Run Applet Program in CMD

Output

You might also like