SlideShare a Scribd company logo
Applets
Dr. P. Victer Paul, Indian Institute of Information Technology Kottayam
2
Topics
 What is Applet?
 Difference b/w Application and Applet
 Restrictions
 Life Cycle of Applet
 Applet States and Methods
 Applet program Structure
 First Applet and Execution
 Embedding Applet in Web Page
 Displaying images using Applets
 Passing Parameters to Applet
 More Samples!!!
Dr. P. Victer Paul, Indian Institute of Information Technology Kottayam
3
Applets
 An applet (little application) is a small program which
should be run within a larger program.
 An applet is a program that is typically embedded in a
Web page and can be run from a browser
 They can be transported over the Internet from one
computer (web server) to another (client computers).
 You need special HTML tag in the Web page to tell the
browser about the applet
 Created by subclassing from the
java.applet.Applet class
 Examples of Java enabled web browsers are Internet
Explorer, Firefox, chrome (only older versions)
Pig is to piglet as Application is to ??
Dr. P. Victer Paul, Indian Institute of Information Technology Kottayam
4
Applet: Accessed over the Web
Hello
Hello Java
<app=
“Hello”>
4
APPLET
Development
“hello.java”
AT
SUN.COM
The Internet
hello.class
AT SUN’S
WEB
SERVER
2 31 5
Create
Applet
tag in
HTML
document
Accessing
from
Your Organisation
The browser
creates
a new
window and
a new thread
and
then runs the
code
Dr. P. Victer Paul, Indian Institute of Information Technology Kottayam
Difference - Applets and Applications
 An applet is basically designed for deploying on the web.
An application is designed to work as a standalone program.
 Applets are created by extending the java.applet.Applet class
There is no such constraint for an application.
 Applets run on any browser.
Applications run using Java interpreter/terminal.
 Execution of applets begin with the init() method. Execution
of applications begins with main() method.
 It is not mandatory to declare main() for an applet.
In case of application, main() has to be included in a public
class.
 Output to an Applet’s window is done by using different AWT
methods such as drawString().
In case of an application System.out.println() method is used.
5Dr. P. Victer Paul, Indian Institute of Information Technology Kottayam
Difference - Applets and Applications
6Dr. P. Victer Paul, Indian Institute of Information Technology Kottayam
7
Restrictions
 Although both the Applets and stand-alone applications
are Java programs, there are certain restrictions are
imposed on Applets due to security concerns:
 They are embedded inside a web page and executed in
browsers.
 They cannot read from or write to the files on local
computer.
 They cannot communicate with other servers on the
network.
 They cannot run any programs from the local
computer.
 They are restricted from using libraries from other
languages.
 The above restrictions ensures that an Applet cannot do
any damage to the local system.Dr. P. Victer Paul, Indian Institute of Information Technology Kottayam
Life cycle of an Applet
 Life cycle of an Applet specifies stages the object has
to pass right from its creation until it is destroyed.
 Every applet inherits a set of default behaviours from
the Applet class. As a result, when an applet is
loaded, it undergoes a series of changes in its state.
 For each event/state, a method is automatically
called.
 The applet states include:
 Initialisation – invokes init()
 Running – invokes start()
 Display – invokes paint()
 Idle – invokes stop()
 Dead/Destroyed State – invokes destroy()
8Dr. P. Victer Paul, Indian Institute of Information Technology Kottayam
9
Applet States
 Initialisation – invokes init() – only once
 Invoked when applet is first loaded.
 Running – invokes start() – more than once
 For the first time, it is called automatically by the
system after init() method execution.
 It is also invoked when applet moves from idle/stop()
state to active state.
 Display – invokes paint() - more than once
 It happens immediately after the applet enters into the
running state. It is responsible for displaying output.
 Idle – invokes stop() - more than once
 It is invoked when the applet is stopped from running.
For example, it occurs when we leave a web page.
 Dead/Destroyed State – invokes destroy() - only once
 This occurs automatically by invoking destroy()
method when we quite the browser.
Dr. P. Victer Paul, Indian Institute of Information Technology Kottayam
Redraw
Applet
stop( )
Start
state
start( ) paint( )
Life cycle of an Applet Contd…
Applet
Working
Applet
Born
Applet
Displayed
Idle
State
Applet
Destroyed
Initialization
state
destroy( )
Destroy
Appletinit( )
10Dr. P. Victer Paul, Indian Institute of Information Technology Kottayam
11
Applet Life Cycle Diagram
Born
Running Idle
Dead
Begin
init()
start()
paint()
stop()
start()
destroy()
End
Dr. P. Victer Paul, Indian Institute of Information Technology Kottayam
12
Applet Program Structure
Dr. P. Victer Paul, Indian Institute of Information Technology Kottayam
13
Building Applet Code: An Example
//HelloWorldApplet.java
import java.applet.Applet;
import java.awt.*;
public class HelloApplet extends Applet {
public void paint(Graphics g) {
g.drawString ("Hello World of Java!",25, 25);
}
}
Dr. P. Victer Paul, Indian Institute of Information Technology Kottayam
14
Embedding Applet in Web Page
<HTML>
<HEAD>
<TITLE>
Hello World Applet
</TITLE>
</HEAD>
<body>
<h1>Hi, This is My First Java Applet on the Web!</h1>
<applet code="HelloApplet.class" width=500 height=400>
</applet>
</body>
</HTML>
Dr. P. Victer Paul, Indian Institute of Information Technology Kottayam
15
Accessing Web page (runs Applet)
Dr. P. Victer Paul, Indian Institute of Information Technology Kottayam
A simple applet
Output
import java.awt.*;
import java.applet.*;
public class FirstApplet extends Applet
{
String str;
public void init()
{
str = "Java is interesting!";
}
public void paint(Graphics g)
{
g.drawString(str, 70, 80);
}
}
16Dr. P. Victer Paul, Indian Institute of Information Technology Kottayam
 Create a HTML page to display the applet
<html>
<applet code=FirstApplet.class width=200 height=200>
</applet>
</html>
 Then type the following at command prompt:
 appletviewer abc.html where abc.html is the name of
the html file.
Creating an Applet
 An applet is compiled using the Java compiler: javac
 javac FirstApplet.java
17Dr. P. Victer Paul, Indian Institute of Information Technology Kottayam
Displaying images using Applets
Output
/*
<applet code = DisplayImage width = 200 height = 200>
</applet>
*/
import java.awt.*;
import java.applet.*;
public class DisplayImage extends Applet
{
Image img;
public void init()
{
img = getImage(getCodeBase(),"duke.gif");
}
public void paint(Graphics g)
{
g.drawImage(img,20,20,this);
}
}
18Dr. P. Victer Paul, Indian Institute of Information Technology Kottayam
Displaying images using Applets
 To display images, we need to make use of the Image
and Graphics classes.
 getCodeBase() method gets the base URL of the applet
 getImage() method returns an Image object which can
be drawn on the screen
 drawImage() takes four parameters – Image object,
location in terms of x and y coordinates and an object
of type ImageObserver
19Dr. P. Victer Paul, Indian Institute of Information Technology Kottayam
20
Sample Graphics methods
 A Graphics is something you can paint on
g.drawRect(x, y, width, height);
g.fillRect(x, y, width, height);
g.drawOval(x, y, width, height);
g.fillOval(x, y, width, height);
g.setColor(Color.red);
g.drawString(“Hello”, 20, 20); Hello
Dr. P. Victer Paul, Indian Institute of Information Technology Kottayam
21
repaint( )
 Call repaint( ) when you have changed something
and want your changes to show up on the screen
 You do not need to call repaint() when something in
Java’s own components (Buttons, TextFields, etc.)
 You do need to call repaint() after drawing commands
(drawRect(...), fillRect(...), drawString(...), etc.)
 repaint( ) is a request--it might not happen
 When you call repaint( ), Java schedules a call to
update(Graphics g)
Dr. P. Victer Paul, Indian Institute of Information Technology Kottayam
22
Passing Parameters to Applet
<HTML>
<HEAD>
<TITLE>
Hello World Applet
</TITLE>
</HEAD>
<body>
<h1>Hi, This is My First Communicating Applet on the Web!</h1>
<APPLET
CODE="HelloAppletMsg.class" width=500 height=400>
<PARAM NAME="Greetings" VALUE="Hello Friend, How are you?">
</APPLET>
</body>
</HTML>Dr. P. Victer Paul, Indian Institute of Information Technology Kottayam
23
Applet Accepting Parameters
//HelloAppletMsg.java
import java.applet.Applet;
import java.awt.*;
public class HelloAppletMsg extends Applet {
String msg;
public void init()
{
msg = getParameter("Greetings");
if( msg == null)
msg = "Hello";
}
public void paint(Graphics g) {
g.drawString (msg,10, 100);
}
} This is name of parameter specified in PARAM tag;
This method returns the value of paramter.
Dr. P. Victer Paul, Indian Institute of Information Technology Kottayam
24
HelloAppletMsg.html
Dr. P. Victer Paul, Indian Institute of Information Technology Kottayam
25
Displaying Numeric Values
//SumNums.java
import java.applet.Applet;
import java.awt.*;
public class SumNums extends Applet {
public void paint(Graphics g) {
int num1 = 10;
int num2 = 20;
int sum = num1 + num2;
String str = "Sum: "+String.valueOf(sum);
g.drawString (str,100, 125);
}
}
Dr. P. Victer Paul, Indian Institute of Information Technology Kottayam
26
SunNums.html
<HTML>
<HEAD>
<TITLE>
Hello World Applet
</TITLE>
</HEAD>
<body>
<h1>Sum of Numbers</h1>
<APPLET CODE="SumNums.class" width=500 height=400>
</APPLET>
</body>
</HTML>
Dr. P. Victer Paul, Indian Institute of Information Technology Kottayam
27
Applet – Sum Numbers
Dr. P. Victer Paul, Indian Institute of Information Technology Kottayam
28
The End…
Dr. P. Victer Paul, Indian Institute of Information Technology Kottayam

More Related Content

What's hot (20)

Introduction to fragments in android
Introduction to fragments in androidIntroduction to fragments in android
Introduction to fragments in android
Prawesh Shrestha
 
Applets
AppletsApplets
Applets
Prabhakaran V M
 
Java Swing
Java SwingJava Swing
Java Swing
Arkadeep Dey
 
JDBC – Java Database Connectivity
JDBC – Java Database ConnectivityJDBC – Java Database Connectivity
JDBC – Java Database Connectivity
Information Technology
 
Java Networking
Java NetworkingJava Networking
Java Networking
Sunil OS
 
Event Handling in java
Event Handling in javaEvent Handling in java
Event Handling in java
Google
 
JDBC ppt
JDBC pptJDBC ppt
JDBC ppt
Rohit Jain
 
PHP - Introduction to Object Oriented Programming with PHP
PHP -  Introduction to  Object Oriented Programming with PHPPHP -  Introduction to  Object Oriented Programming with PHP
PHP - Introduction to Object Oriented Programming with PHP
Vibrant Technologies & Computers
 
Swing and AWT in java
Swing and AWT in javaSwing and AWT in java
Swing and AWT in java
Adil Mehmoood
 
Servlets
ServletsServlets
Servlets
Akshay Ballarpure
 
Asp.net state management
Asp.net state managementAsp.net state management
Asp.net state management
priya Nithya
 
Java Programming
Java ProgrammingJava Programming
Java Programming
Elizabeth alexander
 
Jsp/Servlet
Jsp/ServletJsp/Servlet
Jsp/Servlet
Sunil OS
 
Java 8 Streams
Java 8 StreamsJava 8 Streams
Java 8 Streams
Manvendra Singh
 
Data Types, Variables, and Operators
Data Types, Variables, and OperatorsData Types, Variables, and Operators
Data Types, Variables, and Operators
Marwa Ali Eissa
 
Debugging in visual studio (basic level)
Debugging in visual studio (basic level)Debugging in visual studio (basic level)
Debugging in visual studio (basic level)
Larry Nung
 
How to download and install Python - lesson 2
How to download and install Python - lesson 2How to download and install Python - lesson 2
How to download and install Python - lesson 2
Shohel Rana
 
Jdbc ppt
Jdbc pptJdbc ppt
Jdbc ppt
sandeep54552
 
ASP.NET Page Life Cycle
ASP.NET Page Life CycleASP.NET Page Life Cycle
ASP.NET Page Life Cycle
Abhishek Sur
 
Java Applet
Java AppletJava Applet
Java Applet
jalinder123
 
Introduction to fragments in android
Introduction to fragments in androidIntroduction to fragments in android
Introduction to fragments in android
Prawesh Shrestha
 
Java Networking
Java NetworkingJava Networking
Java Networking
Sunil OS
 
Event Handling in java
Event Handling in javaEvent Handling in java
Event Handling in java
Google
 
PHP - Introduction to Object Oriented Programming with PHP
PHP -  Introduction to  Object Oriented Programming with PHPPHP -  Introduction to  Object Oriented Programming with PHP
PHP - Introduction to Object Oriented Programming with PHP
Vibrant Technologies & Computers
 
Swing and AWT in java
Swing and AWT in javaSwing and AWT in java
Swing and AWT in java
Adil Mehmoood
 
Asp.net state management
Asp.net state managementAsp.net state management
Asp.net state management
priya Nithya
 
Jsp/Servlet
Jsp/ServletJsp/Servlet
Jsp/Servlet
Sunil OS
 
Data Types, Variables, and Operators
Data Types, Variables, and OperatorsData Types, Variables, and Operators
Data Types, Variables, and Operators
Marwa Ali Eissa
 
Debugging in visual studio (basic level)
Debugging in visual studio (basic level)Debugging in visual studio (basic level)
Debugging in visual studio (basic level)
Larry Nung
 
How to download and install Python - lesson 2
How to download and install Python - lesson 2How to download and install Python - lesson 2
How to download and install Python - lesson 2
Shohel Rana
 
ASP.NET Page Life Cycle
ASP.NET Page Life CycleASP.NET Page Life Cycle
ASP.NET Page Life Cycle
Abhishek Sur
 

Similar to Java applet programming concepts (20)

Basic of Applet
Basic of AppletBasic of Applet
Basic of Applet
suraj pandey
 
Applets in Java
Applets in JavaApplets in Java
Applets in Java
RamaPrabha24
 
Applets in Java. Learn java program with applets
Applets in Java. Learn java program with appletsApplets in Java. Learn java program with applets
Applets in Java. Learn java program with applets
halaplay385
 
Advanced programming chapter 2 - Java Applet.pdf
Advanced programming chapter 2 - Java Applet.pdfAdvanced programming chapter 2 - Java Applet.pdf
Advanced programming chapter 2 - Java Applet.pdf
fikadumeuedu
 
Class notes(week 10) on applet programming
Class notes(week 10) on applet programmingClass notes(week 10) on applet programming
Class notes(week 10) on applet programming
Kuntal Bhowmick
 
Unit 7 Java
Unit 7 JavaUnit 7 Java
Unit 7 Java
arnold 7490
 
Appletjava
AppletjavaAppletjava
Appletjava
DEEPIKA T
 
Applet in java new
Applet in java newApplet in java new
Applet in java new
Kavitha713564
 
3. applets
3. applets3. applets
3. applets
AnusAhmad
 
Java applet
Java appletJava applet
Java applet
Elizabeth alexander
 
Java: Java Applets
Java: Java AppletsJava: Java Applets
Java: Java Applets
Tareq Hasan
 
Introduction To Applets methods and simple examples
Introduction To Applets methods  and simple examplesIntroduction To Applets methods  and simple examples
Introduction To Applets methods and simple examples
MsPariyalNituLaxman
 
MSBTE Computer Engineering Java applet.pptx
MSBTE Computer Engineering Java applet.pptxMSBTE Computer Engineering Java applet.pptx
MSBTE Computer Engineering Java applet.pptx
kunalgaikwad1705
 
Applet progming
Applet progmingApplet progming
Applet progming
VIKRANTHMALLIKARJUN
 
Applet Architecture - Introducing Java Applets
Applet Architecture - Introducing Java AppletsApplet Architecture - Introducing Java Applets
Applet Architecture - Introducing Java Applets
amitksaha
 
Applet
AppletApplet
Applet
Priyanka Pradhan
 
Smart material - Unit 3 (2).pdf
Smart material - Unit 3 (2).pdfSmart material - Unit 3 (2).pdf
Smart material - Unit 3 (2).pdf
GayathriRHICETCSESTA
 
Smart material - Unit 3 (1).pdf
Smart material - Unit 3 (1).pdfSmart material - Unit 3 (1).pdf
Smart material - Unit 3 (1).pdf
GayathriRHICETCSESTA
 
applet.pptx
applet.pptxapplet.pptx
applet.pptx
SachinBhosale73
 
Applet and graphics programming
Applet and graphics programmingApplet and graphics programming
Applet and graphics programming
mcanotes
 
Applets in Java. Learn java program with applets
Applets in Java. Learn java program with appletsApplets in Java. Learn java program with applets
Applets in Java. Learn java program with applets
halaplay385
 
Advanced programming chapter 2 - Java Applet.pdf
Advanced programming chapter 2 - Java Applet.pdfAdvanced programming chapter 2 - Java Applet.pdf
Advanced programming chapter 2 - Java Applet.pdf
fikadumeuedu
 
Class notes(week 10) on applet programming
Class notes(week 10) on applet programmingClass notes(week 10) on applet programming
Class notes(week 10) on applet programming
Kuntal Bhowmick
 
Java: Java Applets
Java: Java AppletsJava: Java Applets
Java: Java Applets
Tareq Hasan
 
Introduction To Applets methods and simple examples
Introduction To Applets methods  and simple examplesIntroduction To Applets methods  and simple examples
Introduction To Applets methods and simple examples
MsPariyalNituLaxman
 
MSBTE Computer Engineering Java applet.pptx
MSBTE Computer Engineering Java applet.pptxMSBTE Computer Engineering Java applet.pptx
MSBTE Computer Engineering Java applet.pptx
kunalgaikwad1705
 
Applet Architecture - Introducing Java Applets
Applet Architecture - Introducing Java AppletsApplet Architecture - Introducing Java Applets
Applet Architecture - Introducing Java Applets
amitksaha
 
Applet and graphics programming
Applet and graphics programmingApplet and graphics programming
Applet and graphics programming
mcanotes
 
Ad

More from Victer Paul (13)

OOAD - UML - Sequence and Communication Diagrams - Lab
OOAD - UML - Sequence and Communication Diagrams - LabOOAD - UML - Sequence and Communication Diagrams - Lab
OOAD - UML - Sequence and Communication Diagrams - Lab
Victer Paul
 
OOAD - UML - Class and Object Diagrams - Lab
OOAD - UML - Class and Object Diagrams - LabOOAD - UML - Class and Object Diagrams - Lab
OOAD - UML - Class and Object Diagrams - Lab
Victer Paul
 
OOAD - Systems and Object Orientation Concepts
OOAD - Systems and Object Orientation ConceptsOOAD - Systems and Object Orientation Concepts
OOAD - Systems and Object Orientation Concepts
Victer Paul
 
Java - Strings Concepts
Java - Strings ConceptsJava - Strings Concepts
Java - Strings Concepts
Victer Paul
 
Java - Packages Concepts
Java - Packages ConceptsJava - Packages Concepts
Java - Packages Concepts
Victer Paul
 
Java - OOPS and Java Basics
Java - OOPS and Java BasicsJava - OOPS and Java Basics
Java - OOPS and Java Basics
Victer Paul
 
Java - Exception Handling Concepts
Java - Exception Handling ConceptsJava - Exception Handling Concepts
Java - Exception Handling Concepts
Victer Paul
 
Java - Class Structure
Java - Class StructureJava - Class Structure
Java - Class Structure
Victer Paul
 
Java - Object Oriented Programming Concepts
Java - Object Oriented Programming ConceptsJava - Object Oriented Programming Concepts
Java - Object Oriented Programming Concepts
Victer Paul
 
Java - Basic Concepts
Java - Basic ConceptsJava - Basic Concepts
Java - Basic Concepts
Victer Paul
 
Java - File Input Output Concepts
Java - File Input Output ConceptsJava - File Input Output Concepts
Java - File Input Output Concepts
Victer Paul
 
Java - Inheritance Concepts
Java - Inheritance ConceptsJava - Inheritance Concepts
Java - Inheritance Concepts
Victer Paul
 
Java - Arrays Concepts
Java - Arrays ConceptsJava - Arrays Concepts
Java - Arrays Concepts
Victer Paul
 
OOAD - UML - Sequence and Communication Diagrams - Lab
OOAD - UML - Sequence and Communication Diagrams - LabOOAD - UML - Sequence and Communication Diagrams - Lab
OOAD - UML - Sequence and Communication Diagrams - Lab
Victer Paul
 
OOAD - UML - Class and Object Diagrams - Lab
OOAD - UML - Class and Object Diagrams - LabOOAD - UML - Class and Object Diagrams - Lab
OOAD - UML - Class and Object Diagrams - Lab
Victer Paul
 
OOAD - Systems and Object Orientation Concepts
OOAD - Systems and Object Orientation ConceptsOOAD - Systems and Object Orientation Concepts
OOAD - Systems and Object Orientation Concepts
Victer Paul
 
Java - Strings Concepts
Java - Strings ConceptsJava - Strings Concepts
Java - Strings Concepts
Victer Paul
 
Java - Packages Concepts
Java - Packages ConceptsJava - Packages Concepts
Java - Packages Concepts
Victer Paul
 
Java - OOPS and Java Basics
Java - OOPS and Java BasicsJava - OOPS and Java Basics
Java - OOPS and Java Basics
Victer Paul
 
Java - Exception Handling Concepts
Java - Exception Handling ConceptsJava - Exception Handling Concepts
Java - Exception Handling Concepts
Victer Paul
 
Java - Class Structure
Java - Class StructureJava - Class Structure
Java - Class Structure
Victer Paul
 
Java - Object Oriented Programming Concepts
Java - Object Oriented Programming ConceptsJava - Object Oriented Programming Concepts
Java - Object Oriented Programming Concepts
Victer Paul
 
Java - Basic Concepts
Java - Basic ConceptsJava - Basic Concepts
Java - Basic Concepts
Victer Paul
 
Java - File Input Output Concepts
Java - File Input Output ConceptsJava - File Input Output Concepts
Java - File Input Output Concepts
Victer Paul
 
Java - Inheritance Concepts
Java - Inheritance ConceptsJava - Inheritance Concepts
Java - Inheritance Concepts
Victer Paul
 
Java - Arrays Concepts
Java - Arrays ConceptsJava - Arrays Concepts
Java - Arrays Concepts
Victer Paul
 
Ad

Recently uploaded (20)

Oracle Cloud and AI Specialization Program
Oracle Cloud and AI Specialization ProgramOracle Cloud and AI Specialization Program
Oracle Cloud and AI Specialization Program
VICTOR MAESTRE RAMIREZ
 
How Advanced Environmental Detection Is Revolutionizing Oil & Gas Safety.pdf
How Advanced Environmental Detection Is Revolutionizing Oil & Gas Safety.pdfHow Advanced Environmental Detection Is Revolutionizing Oil & Gas Safety.pdf
How Advanced Environmental Detection Is Revolutionizing Oil & Gas Safety.pdf
Rejig Digital
 
Boosting MySQL with Vector Search -THE VECTOR SEARCH CONFERENCE 2025 .pdf
Boosting MySQL with Vector Search -THE VECTOR SEARCH CONFERENCE 2025 .pdfBoosting MySQL with Vector Search -THE VECTOR SEARCH CONFERENCE 2025 .pdf
Boosting MySQL with Vector Search -THE VECTOR SEARCH CONFERENCE 2025 .pdf
Alkin Tezuysal
 
Introduction to Typescript - GDG On Campus EUE
Introduction to Typescript - GDG On Campus EUEIntroduction to Typescript - GDG On Campus EUE
Introduction to Typescript - GDG On Campus EUE
Google Developer Group On Campus European Universities in Egypt
 
Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...
Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...
Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...
NTT DATA Technology & Innovation
 
Secure Access with Azure Active Directory
Secure Access with Azure Active DirectorySecure Access with Azure Active Directory
Secure Access with Azure Active Directory
VICTOR MAESTRE RAMIREZ
 
Your startup on AWS - How to architect and maintain a Lean and Mean account J...
Your startup on AWS - How to architect and maintain a Lean and Mean account J...Your startup on AWS - How to architect and maintain a Lean and Mean account J...
Your startup on AWS - How to architect and maintain a Lean and Mean account J...
angelo60207
 
Agentic AI: Beyond the Buzz- LangGraph Studio V2
Agentic AI: Beyond the Buzz- LangGraph Studio V2Agentic AI: Beyond the Buzz- LangGraph Studio V2
Agentic AI: Beyond the Buzz- LangGraph Studio V2
Shashikant Jagtap
 
Oracle Cloud Infrastructure Generative AI Professional
Oracle Cloud Infrastructure Generative AI ProfessionalOracle Cloud Infrastructure Generative AI Professional
Oracle Cloud Infrastructure Generative AI Professional
VICTOR MAESTRE RAMIREZ
 
vertical-cnc-processing-centers-drillteq-v-200-en.pdf
vertical-cnc-processing-centers-drillteq-v-200-en.pdfvertical-cnc-processing-centers-drillteq-v-200-en.pdf
vertical-cnc-processing-centers-drillteq-v-200-en.pdf
AmirStern2
 
Azure vs AWS Which Cloud Platform Is Best for Your Business in 2025
Azure vs AWS  Which Cloud Platform Is Best for Your Business in 2025Azure vs AWS  Which Cloud Platform Is Best for Your Business in 2025
Azure vs AWS Which Cloud Platform Is Best for Your Business in 2025
Infrassist Technologies Pvt. Ltd.
 
Viral>Wondershare Filmora 14.5.18.12900 Crack Free Download
Viral>Wondershare Filmora 14.5.18.12900 Crack Free DownloadViral>Wondershare Filmora 14.5.18.12900 Crack Free Download
Viral>Wondershare Filmora 14.5.18.12900 Crack Free Download
Puppy jhon
 
Ben Blair - Operating Safely in a Vibe Coding World
Ben Blair - Operating Safely in a Vibe Coding WorldBen Blair - Operating Safely in a Vibe Coding World
Ben Blair - Operating Safely in a Vibe Coding World
AWS Chicago
 
Kubernetes Security Act Now Before It’s Too Late
Kubernetes Security Act Now Before It’s Too LateKubernetes Security Act Now Before It’s Too Late
Kubernetes Security Act Now Before It’s Too Late
Michael Furman
 
Developing Schemas with FME and Excel - Peak of Data & AI 2025
Developing Schemas with FME and Excel - Peak of Data & AI 2025Developing Schemas with FME and Excel - Peak of Data & AI 2025
Developing Schemas with FME and Excel - Peak of Data & AI 2025
Safe Software
 
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
Safe Software
 
Murdledescargadarkweb.pdfvolumen1 100 elementary
Murdledescargadarkweb.pdfvolumen1 100 elementaryMurdledescargadarkweb.pdfvolumen1 100 elementary
Murdledescargadarkweb.pdfvolumen1 100 elementary
JorgeSemperteguiMont
 
Trends Artificial Intelligence - Mary Meeker
Trends Artificial Intelligence - Mary MeekerTrends Artificial Intelligence - Mary Meeker
Trends Artificial Intelligence - Mary Meeker
Clive Dickens
 
Your startup on AWS - How to architect and maintain a Lean and Mean account
Your startup on AWS - How to architect and maintain a Lean and Mean accountYour startup on AWS - How to architect and maintain a Lean and Mean account
Your startup on AWS - How to architect and maintain a Lean and Mean account
angelo60207
 
Domino IQ – What to Expect, First Steps and Use Cases
Domino IQ – What to Expect, First Steps and Use CasesDomino IQ – What to Expect, First Steps and Use Cases
Domino IQ – What to Expect, First Steps and Use Cases
panagenda
 
Oracle Cloud and AI Specialization Program
Oracle Cloud and AI Specialization ProgramOracle Cloud and AI Specialization Program
Oracle Cloud and AI Specialization Program
VICTOR MAESTRE RAMIREZ
 
How Advanced Environmental Detection Is Revolutionizing Oil & Gas Safety.pdf
How Advanced Environmental Detection Is Revolutionizing Oil & Gas Safety.pdfHow Advanced Environmental Detection Is Revolutionizing Oil & Gas Safety.pdf
How Advanced Environmental Detection Is Revolutionizing Oil & Gas Safety.pdf
Rejig Digital
 
Boosting MySQL with Vector Search -THE VECTOR SEARCH CONFERENCE 2025 .pdf
Boosting MySQL with Vector Search -THE VECTOR SEARCH CONFERENCE 2025 .pdfBoosting MySQL with Vector Search -THE VECTOR SEARCH CONFERENCE 2025 .pdf
Boosting MySQL with Vector Search -THE VECTOR SEARCH CONFERENCE 2025 .pdf
Alkin Tezuysal
 
Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...
Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...
Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...
NTT DATA Technology & Innovation
 
Secure Access with Azure Active Directory
Secure Access with Azure Active DirectorySecure Access with Azure Active Directory
Secure Access with Azure Active Directory
VICTOR MAESTRE RAMIREZ
 
Your startup on AWS - How to architect and maintain a Lean and Mean account J...
Your startup on AWS - How to architect and maintain a Lean and Mean account J...Your startup on AWS - How to architect and maintain a Lean and Mean account J...
Your startup on AWS - How to architect and maintain a Lean and Mean account J...
angelo60207
 
Agentic AI: Beyond the Buzz- LangGraph Studio V2
Agentic AI: Beyond the Buzz- LangGraph Studio V2Agentic AI: Beyond the Buzz- LangGraph Studio V2
Agentic AI: Beyond the Buzz- LangGraph Studio V2
Shashikant Jagtap
 
Oracle Cloud Infrastructure Generative AI Professional
Oracle Cloud Infrastructure Generative AI ProfessionalOracle Cloud Infrastructure Generative AI Professional
Oracle Cloud Infrastructure Generative AI Professional
VICTOR MAESTRE RAMIREZ
 
vertical-cnc-processing-centers-drillteq-v-200-en.pdf
vertical-cnc-processing-centers-drillteq-v-200-en.pdfvertical-cnc-processing-centers-drillteq-v-200-en.pdf
vertical-cnc-processing-centers-drillteq-v-200-en.pdf
AmirStern2
 
Azure vs AWS Which Cloud Platform Is Best for Your Business in 2025
Azure vs AWS  Which Cloud Platform Is Best for Your Business in 2025Azure vs AWS  Which Cloud Platform Is Best for Your Business in 2025
Azure vs AWS Which Cloud Platform Is Best for Your Business in 2025
Infrassist Technologies Pvt. Ltd.
 
Viral>Wondershare Filmora 14.5.18.12900 Crack Free Download
Viral>Wondershare Filmora 14.5.18.12900 Crack Free DownloadViral>Wondershare Filmora 14.5.18.12900 Crack Free Download
Viral>Wondershare Filmora 14.5.18.12900 Crack Free Download
Puppy jhon
 
Ben Blair - Operating Safely in a Vibe Coding World
Ben Blair - Operating Safely in a Vibe Coding WorldBen Blair - Operating Safely in a Vibe Coding World
Ben Blair - Operating Safely in a Vibe Coding World
AWS Chicago
 
Kubernetes Security Act Now Before It’s Too Late
Kubernetes Security Act Now Before It’s Too LateKubernetes Security Act Now Before It’s Too Late
Kubernetes Security Act Now Before It’s Too Late
Michael Furman
 
Developing Schemas with FME and Excel - Peak of Data & AI 2025
Developing Schemas with FME and Excel - Peak of Data & AI 2025Developing Schemas with FME and Excel - Peak of Data & AI 2025
Developing Schemas with FME and Excel - Peak of Data & AI 2025
Safe Software
 
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
Safe Software
 
Murdledescargadarkweb.pdfvolumen1 100 elementary
Murdledescargadarkweb.pdfvolumen1 100 elementaryMurdledescargadarkweb.pdfvolumen1 100 elementary
Murdledescargadarkweb.pdfvolumen1 100 elementary
JorgeSemperteguiMont
 
Trends Artificial Intelligence - Mary Meeker
Trends Artificial Intelligence - Mary MeekerTrends Artificial Intelligence - Mary Meeker
Trends Artificial Intelligence - Mary Meeker
Clive Dickens
 
Your startup on AWS - How to architect and maintain a Lean and Mean account
Your startup on AWS - How to architect and maintain a Lean and Mean accountYour startup on AWS - How to architect and maintain a Lean and Mean account
Your startup on AWS - How to architect and maintain a Lean and Mean account
angelo60207
 
Domino IQ – What to Expect, First Steps and Use Cases
Domino IQ – What to Expect, First Steps and Use CasesDomino IQ – What to Expect, First Steps and Use Cases
Domino IQ – What to Expect, First Steps and Use Cases
panagenda
 

Java applet programming concepts

  • 1. Applets Dr. P. Victer Paul, Indian Institute of Information Technology Kottayam
  • 2. 2 Topics  What is Applet?  Difference b/w Application and Applet  Restrictions  Life Cycle of Applet  Applet States and Methods  Applet program Structure  First Applet and Execution  Embedding Applet in Web Page  Displaying images using Applets  Passing Parameters to Applet  More Samples!!! Dr. P. Victer Paul, Indian Institute of Information Technology Kottayam
  • 3. 3 Applets  An applet (little application) is a small program which should be run within a larger program.  An applet is a program that is typically embedded in a Web page and can be run from a browser  They can be transported over the Internet from one computer (web server) to another (client computers).  You need special HTML tag in the Web page to tell the browser about the applet  Created by subclassing from the java.applet.Applet class  Examples of Java enabled web browsers are Internet Explorer, Firefox, chrome (only older versions) Pig is to piglet as Application is to ?? Dr. P. Victer Paul, Indian Institute of Information Technology Kottayam
  • 4. 4 Applet: Accessed over the Web Hello Hello Java <app= “Hello”> 4 APPLET Development “hello.java” AT SUN.COM The Internet hello.class AT SUN’S WEB SERVER 2 31 5 Create Applet tag in HTML document Accessing from Your Organisation The browser creates a new window and a new thread and then runs the code Dr. P. Victer Paul, Indian Institute of Information Technology Kottayam
  • 5. Difference - Applets and Applications  An applet is basically designed for deploying on the web. An application is designed to work as a standalone program.  Applets are created by extending the java.applet.Applet class There is no such constraint for an application.  Applets run on any browser. Applications run using Java interpreter/terminal.  Execution of applets begin with the init() method. Execution of applications begins with main() method.  It is not mandatory to declare main() for an applet. In case of application, main() has to be included in a public class.  Output to an Applet’s window is done by using different AWT methods such as drawString(). In case of an application System.out.println() method is used. 5Dr. P. Victer Paul, Indian Institute of Information Technology Kottayam
  • 6. Difference - Applets and Applications 6Dr. P. Victer Paul, Indian Institute of Information Technology Kottayam
  • 7. 7 Restrictions  Although both the Applets and stand-alone applications are Java programs, there are certain restrictions are imposed on Applets due to security concerns:  They are embedded inside a web page and executed in browsers.  They cannot read from or write to the files on local computer.  They cannot communicate with other servers on the network.  They cannot run any programs from the local computer.  They are restricted from using libraries from other languages.  The above restrictions ensures that an Applet cannot do any damage to the local system.Dr. P. Victer Paul, Indian Institute of Information Technology Kottayam
  • 8. Life cycle of an Applet  Life cycle of an Applet specifies stages the object has to pass right from its creation until it is destroyed.  Every applet inherits a set of default behaviours from the Applet class. As a result, when an applet is loaded, it undergoes a series of changes in its state.  For each event/state, a method is automatically called.  The applet states include:  Initialisation – invokes init()  Running – invokes start()  Display – invokes paint()  Idle – invokes stop()  Dead/Destroyed State – invokes destroy() 8Dr. P. Victer Paul, Indian Institute of Information Technology Kottayam
  • 9. 9 Applet States  Initialisation – invokes init() – only once  Invoked when applet is first loaded.  Running – invokes start() – more than once  For the first time, it is called automatically by the system after init() method execution.  It is also invoked when applet moves from idle/stop() state to active state.  Display – invokes paint() - more than once  It happens immediately after the applet enters into the running state. It is responsible for displaying output.  Idle – invokes stop() - more than once  It is invoked when the applet is stopped from running. For example, it occurs when we leave a web page.  Dead/Destroyed State – invokes destroy() - only once  This occurs automatically by invoking destroy() method when we quite the browser. Dr. P. Victer Paul, Indian Institute of Information Technology Kottayam
  • 10. Redraw Applet stop( ) Start state start( ) paint( ) Life cycle of an Applet Contd… Applet Working Applet Born Applet Displayed Idle State Applet Destroyed Initialization state destroy( ) Destroy Appletinit( ) 10Dr. P. Victer Paul, Indian Institute of Information Technology Kottayam
  • 11. 11 Applet Life Cycle Diagram Born Running Idle Dead Begin init() start() paint() stop() start() destroy() End Dr. P. Victer Paul, Indian Institute of Information Technology Kottayam
  • 12. 12 Applet Program Structure Dr. P. Victer Paul, Indian Institute of Information Technology Kottayam
  • 13. 13 Building Applet Code: An Example //HelloWorldApplet.java import java.applet.Applet; import java.awt.*; public class HelloApplet extends Applet { public void paint(Graphics g) { g.drawString ("Hello World of Java!",25, 25); } } Dr. P. Victer Paul, Indian Institute of Information Technology Kottayam
  • 14. 14 Embedding Applet in Web Page <HTML> <HEAD> <TITLE> Hello World Applet </TITLE> </HEAD> <body> <h1>Hi, This is My First Java Applet on the Web!</h1> <applet code="HelloApplet.class" width=500 height=400> </applet> </body> </HTML> Dr. P. Victer Paul, Indian Institute of Information Technology Kottayam
  • 15. 15 Accessing Web page (runs Applet) Dr. P. Victer Paul, Indian Institute of Information Technology Kottayam
  • 16. A simple applet Output import java.awt.*; import java.applet.*; public class FirstApplet extends Applet { String str; public void init() { str = "Java is interesting!"; } public void paint(Graphics g) { g.drawString(str, 70, 80); } } 16Dr. P. Victer Paul, Indian Institute of Information Technology Kottayam
  • 17.  Create a HTML page to display the applet <html> <applet code=FirstApplet.class width=200 height=200> </applet> </html>  Then type the following at command prompt:  appletviewer abc.html where abc.html is the name of the html file. Creating an Applet  An applet is compiled using the Java compiler: javac  javac FirstApplet.java 17Dr. P. Victer Paul, Indian Institute of Information Technology Kottayam
  • 18. Displaying images using Applets Output /* <applet code = DisplayImage width = 200 height = 200> </applet> */ import java.awt.*; import java.applet.*; public class DisplayImage extends Applet { Image img; public void init() { img = getImage(getCodeBase(),"duke.gif"); } public void paint(Graphics g) { g.drawImage(img,20,20,this); } } 18Dr. P. Victer Paul, Indian Institute of Information Technology Kottayam
  • 19. Displaying images using Applets  To display images, we need to make use of the Image and Graphics classes.  getCodeBase() method gets the base URL of the applet  getImage() method returns an Image object which can be drawn on the screen  drawImage() takes four parameters – Image object, location in terms of x and y coordinates and an object of type ImageObserver 19Dr. P. Victer Paul, Indian Institute of Information Technology Kottayam
  • 20. 20 Sample Graphics methods  A Graphics is something you can paint on g.drawRect(x, y, width, height); g.fillRect(x, y, width, height); g.drawOval(x, y, width, height); g.fillOval(x, y, width, height); g.setColor(Color.red); g.drawString(“Hello”, 20, 20); Hello Dr. P. Victer Paul, Indian Institute of Information Technology Kottayam
  • 21. 21 repaint( )  Call repaint( ) when you have changed something and want your changes to show up on the screen  You do not need to call repaint() when something in Java’s own components (Buttons, TextFields, etc.)  You do need to call repaint() after drawing commands (drawRect(...), fillRect(...), drawString(...), etc.)  repaint( ) is a request--it might not happen  When you call repaint( ), Java schedules a call to update(Graphics g) Dr. P. Victer Paul, Indian Institute of Information Technology Kottayam
  • 22. 22 Passing Parameters to Applet <HTML> <HEAD> <TITLE> Hello World Applet </TITLE> </HEAD> <body> <h1>Hi, This is My First Communicating Applet on the Web!</h1> <APPLET CODE="HelloAppletMsg.class" width=500 height=400> <PARAM NAME="Greetings" VALUE="Hello Friend, How are you?"> </APPLET> </body> </HTML>Dr. P. Victer Paul, Indian Institute of Information Technology Kottayam
  • 23. 23 Applet Accepting Parameters //HelloAppletMsg.java import java.applet.Applet; import java.awt.*; public class HelloAppletMsg extends Applet { String msg; public void init() { msg = getParameter("Greetings"); if( msg == null) msg = "Hello"; } public void paint(Graphics g) { g.drawString (msg,10, 100); } } This is name of parameter specified in PARAM tag; This method returns the value of paramter. Dr. P. Victer Paul, Indian Institute of Information Technology Kottayam
  • 24. 24 HelloAppletMsg.html Dr. P. Victer Paul, Indian Institute of Information Technology Kottayam
  • 25. 25 Displaying Numeric Values //SumNums.java import java.applet.Applet; import java.awt.*; public class SumNums extends Applet { public void paint(Graphics g) { int num1 = 10; int num2 = 20; int sum = num1 + num2; String str = "Sum: "+String.valueOf(sum); g.drawString (str,100, 125); } } Dr. P. Victer Paul, Indian Institute of Information Technology Kottayam
  • 26. 26 SunNums.html <HTML> <HEAD> <TITLE> Hello World Applet </TITLE> </HEAD> <body> <h1>Sum of Numbers</h1> <APPLET CODE="SumNums.class" width=500 height=400> </APPLET> </body> </HTML> Dr. P. Victer Paul, Indian Institute of Information Technology Kottayam
  • 27. 27 Applet – Sum Numbers Dr. P. Victer Paul, Indian Institute of Information Technology Kottayam
  • 28. 28 The End… Dr. P. Victer Paul, Indian Institute of Information Technology Kottayam