SlideShare a Scribd company logo
Java Applets
Introduction to Java Applet Programs
• Applications are stand alone programs
– executed with Java interpreter
• Applet is a small program
– can be placed on a web page
– will be executed by the web browser
– give web pages “dynamic content”
2
Java Applets
• Built using one of general definitions of
applets
– Applet class
– JAapplet class
• Java applets are usually graphical
– Draw graphics in a defined screen area
– Enable user interaction with GUI elements
3
Java Applet Classes
• Abstract Windowing Toolkit AWT
– Earlier versions of Java
– Applet class is one of the AWT components
• Java Foundation Classes JFC
– Extension to Java in 1997
– Has a collection of Swing components for
enhanced GUIs
– Swing component classes begin with J
4
Java Applets
• Applets are Java programs that can be embedded in
HTML documents
– To run an applet you must create a .html file which
references the applet
– Ready to Program also will run an applet
• When browser loads Web page containing applet
– Applet downloads into Web browser
– begins execution
• Can be tested using appletviewer program
5
Contrast Application with Applet
Application Applet
•Object class extended
•Class not declared public
•Has a main()
•static keyword used
•Uses System.exit(1)
•JApplet class extended
•class declared to be public
•init() instead of main()
•init() not declared with static
keyword
6
Applet Declaration
• Syntax (note difference from application
declaration)
public class ClassName extends JAapplet
7
ClassName is an
object that will be a
subclass of JApplet
Body of an Applet
• Note there is no main() method in an applet
– JApplet class provides other methods instead of
a main method
• First method executed is the init() method
8
Applets
• Applet
– Program that runs in
• appletviewer (test utility for applets)
• Web browser (IE, Communicator)
– Executes when HTML (Hypertext Markup Language)
document containing applet is opened
– Applications run in command windows
• Notes
– Focus on fundamental programming concepts first
• Explanations will come later
9
Applets and Web Pages – HTML
• Applets embedded in a web page
– Executed when web page loaded by browser
• Web pages structured with HTML codes
–HyperText Mark-up Language
• Syntax
<command>
. . .
</command>
10
Turns format onTurns format on
Turns the format offTurns the format off
Applets and Web Pages – HTML
• Embedding Java applets
– Insert applet tags
<APPLET>
</APPLET>
• Call the specific applet by its file name
<APPLET CODE = "Whatever.class"
WIDTH = nnn HEIGHT = mmmm>
<APPLET>
Where nnn and mmm are specific pixel sizes
11
Applets and Web Pages – HTML
• Create the web page
code using a text
editor
• Save it with an .html
suffix
• Open this file with
appletviewer or with
a web browser that
supports Java
• Java Plug-in must be
installed (part of
J2SDK 1.4.1 from Sun)
12
<HTML>
<HEAD>
</HEAD>
<BODY>
<APPLET CODE = . . . >
</APPLET>
</BODY>
</HTML>
Applets and Web Pages – HTML
• Client Web browser anywhere can access this
web page from its host server
• Embedded Java applet runs on client browser
(of any type platform)
• This means a client anywhere on any type of
platform can run a piece of software
developed on any other type of platform
13
Platform Independence
Thinking About Objects
• Java an object-oriented language
– However, Java has constructs from structured
programming
• Object orientation
– Natural way to think about world and writing computer
programs
• Object-oriented programming models the real world
– Attributes - properties of objects
• Size, shape, color, weight, etc.
– Behaviors - actions that objects can perform
• A ball rolls, bounces, inflates and deflates
14
Thinking About Objects
• Object orientation (continued)
– Inheritance
• New classes of objects absorb characteristics of existing
classes
– Information hiding
• Objects usually do not know how other objects are
implemented
• We can drive cars without knowing how every part
works internally
15
Thinking About Objects
Class - unit of Java programming
• Java focuses on nouns (classes)
– C focuses on verbs and is action oriented
• Contain methods
– Implement behaviors
• Contain data
– Implement attributes
• Classes are reusable
– Standardized, interchangeable parts
16
A Simple Java Applet: Drawing a String
• Figure 3.6 – a welcome message applet
• The .html code to run the applet in a browser
• The program output shown in the Applet
Viewer
17
<html>
<applet code = "WelcomeApplet.class" width = "300" height = "45">
</applet>
</html>
<html>
<applet code = "WelcomeApplet.class" width = "300" height = "45">
</applet>
</html>
Running the Applet
• Compile
– Use Ready to Program
– If no errors, bytecodes stored in
WelcomeApplet.class
• We must create an HTML file
– Loads the applet into appletviewer or a browser
– Ends in .htm or .html
• To execute an applet
– Create an HTML file indicating which applet the browser
(or appletviewer) should load and execute
18
Running the Applet - Alternatively
• Run from within Ready to Program
• Prompt for applet window size appears
• Applet window runs
19
20
import allows us to use
predefined classes (allowing
us to use applets and
graphics, in this case).
extends allows us to inherit the
capabilities of class JApplet.
Method paint is guaranteed to
be called in all applets. Its first
line must be defined as above.
Running An Applet
import java.applet.Applet;
import java.awt.Graphics;
public class HelloApplet extends Applet {
public void paint (Graphics g)
{
g.drawString ("Hello. Welcome to",25,25);
g.drawString ("Java Programming",25,40);
}
}
import java.applet.Applet;
import java.awt.Graphics;
public class HelloApplet extends Applet {
public void paint (Graphics g)
{
g.drawString ("Hello. Welcome to",25,25);
g.drawString ("Java Programming",25,40);
}
}
21
• Enter this text into your
Ready to Program editor
• Compile the Java code
• Enter this text into your
Ready to Program editor
• Compile the Java code
Running An Applet
• Now create an .html file to run the applet
• Save it as HelloApplet.html
• Make sure you save it in the same directory as
the .java file
22
<html>
<applet code = "HelloApplet.class" width=275, height = 100>
</applet>
</html>
<html>
<applet code = "HelloApplet.class" width=275, height = 100>
</applet>
</html>

More Related Content

PPT
GUI Programming In Java
yht4ever
 
PPTX
04 activities and activity life cycle
Sokngim Sa
 
PDF
Strings IN C
yndaravind
 
PPT
Css
Manav Prasad
 
PPT
Java layoutmanager
Arati Gadgil
 
PPT
Network programming in Java
Tushar B Kute
 
PPTX
DEFINE FRAME AND FRAME SET WITH A EXAMPLE
Vaibhav Sinha
 
PPT
Applet life cycle
myrajendra
 
GUI Programming In Java
yht4ever
 
04 activities and activity life cycle
Sokngim Sa
 
Strings IN C
yndaravind
 
Java layoutmanager
Arati Gadgil
 
Network programming in Java
Tushar B Kute
 
DEFINE FRAME AND FRAME SET WITH A EXAMPLE
Vaibhav Sinha
 
Applet life cycle
myrajendra
 

What's hot (20)

PPT
android layouts
Deepa Rani
 
PDF
Android Fragment
Kan-Han (John) Lu
 
PPTX
Applets in java
Wani Zahoor
 
PPT
Cascading Style Sheets(CSS)
Reshmi Rajan
 
PPS
Java applets
Srinath Dhayalamoorthy
 
PPT
Introduction to Java Programming, Basic Structure, variables Data type, input...
Mr. Akaash
 
PPTX
Java Swing
Arkadeep Dey
 
PPT
Java Presentation
pm2214
 
PPTX
Kotlin Jetpack Tutorial
Simplilearn
 
PPT
Php forms
Anne Lee
 
PPTX
Java applet - java
Rubaya Mim
 
PDF
Jetpack Compose a new way to implement UI on Android
Nelson Glauber Leal
 
PPTX
Introduction to java
Sandeep Rawat
 
PPTX
Java Swing
Komal Gandhi
 
PPT
Java Networking
Sunil OS
 
PPTX
Awt, Swing, Layout managers
swapnac12
 
PDF
JAVA PROGRAMMING- GUI Programming with Swing - The Swing Buttons
Jyothishmathi Institute of Technology and Science Karimnagar
 
PPTX
The Complete HTML
Rohit Buddabathina
 
PPTX
Introduction to Koltin for Android Part I
Atif AbbAsi
 
android layouts
Deepa Rani
 
Android Fragment
Kan-Han (John) Lu
 
Applets in java
Wani Zahoor
 
Cascading Style Sheets(CSS)
Reshmi Rajan
 
Introduction to Java Programming, Basic Structure, variables Data type, input...
Mr. Akaash
 
Java Swing
Arkadeep Dey
 
Java Presentation
pm2214
 
Kotlin Jetpack Tutorial
Simplilearn
 
Php forms
Anne Lee
 
Java applet - java
Rubaya Mim
 
Jetpack Compose a new way to implement UI on Android
Nelson Glauber Leal
 
Introduction to java
Sandeep Rawat
 
Java Swing
Komal Gandhi
 
Java Networking
Sunil OS
 
Awt, Swing, Layout managers
swapnac12
 
JAVA PROGRAMMING- GUI Programming with Swing - The Swing Buttons
Jyothishmathi Institute of Technology and Science Karimnagar
 
The Complete HTML
Rohit Buddabathina
 
Introduction to Koltin for Android Part I
Atif AbbAsi
 
Ad

Similar to JAVA APPLET BASICS (20)

PDF
Java applets and working principles
DAZZLING DAZZLING
 
PPTX
MSBTE Computer Engineering Java applet.pptx
kunalgaikwad1705
 
PDF
Class notes(week 10) on applet programming
Kuntal Bhowmick
 
PPTX
applet.pptx
SachinBhosale73
 
PPT
Slide8appletv2 091028110313-phpapp01
Abhishek Khune
 
PPT
Jsp applet
Sanoj Kumar
 
PPTX
3. applets
AnusAhmad
 
PDF
Chapter_7_-_EV_-_OOP[1].pdf
zekishamanch
 
PDF
27 applet programming
Ravindra Rathore
 
PPTX
Introduction To Applets methods and simple examples
MsPariyalNituLaxman
 
PPT
Java: Java Applets
Tareq Hasan
 
PPTX
OOP Lecture 22-JApplet.pptx
Tanzila Kehkashan
 
PPTX
Applet Programming in Advance Java Programming
jayshah562401
 
DOCX
Class notes(week 10) on applet programming
Kuntal Bhowmick
 
PPTX
Applet1 (1).pptx
FahanaAbdulVahab
 
PPTX
Applet.pptx
LakachewYezihalem
 
PDF
B.Sc. III(VI Sem) Advance Java Unit2: Appet
Assistant Professor, Shri Shivaji Science College, Amravati
 
PPTX
Applets in Java. Learn java program with applets
halaplay385
 
PDF
UNIT-1-AJAVA.pdf
PriyanshiPrajapati27
 
PPTX
Applet intro
Nitin Birari
 
Java applets and working principles
DAZZLING DAZZLING
 
MSBTE Computer Engineering Java applet.pptx
kunalgaikwad1705
 
Class notes(week 10) on applet programming
Kuntal Bhowmick
 
applet.pptx
SachinBhosale73
 
Slide8appletv2 091028110313-phpapp01
Abhishek Khune
 
Jsp applet
Sanoj Kumar
 
3. applets
AnusAhmad
 
Chapter_7_-_EV_-_OOP[1].pdf
zekishamanch
 
27 applet programming
Ravindra Rathore
 
Introduction To Applets methods and simple examples
MsPariyalNituLaxman
 
Java: Java Applets
Tareq Hasan
 
OOP Lecture 22-JApplet.pptx
Tanzila Kehkashan
 
Applet Programming in Advance Java Programming
jayshah562401
 
Class notes(week 10) on applet programming
Kuntal Bhowmick
 
Applet1 (1).pptx
FahanaAbdulVahab
 
Applet.pptx
LakachewYezihalem
 
B.Sc. III(VI Sem) Advance Java Unit2: Appet
Assistant Professor, Shri Shivaji Science College, Amravati
 
Applets in Java. Learn java program with applets
halaplay385
 
UNIT-1-AJAVA.pdf
PriyanshiPrajapati27
 
Applet intro
Nitin Birari
 
Ad

Recently uploaded (20)

PPTX
Fluid Mechanics, Module 3: Basics of Fluid Mechanics
Dr. Rahul Kumar
 
PPTX
Lesson 3_Tessellation.pptx finite Mathematics
quakeplayz54
 
PDF
ETO & MEO Certificate of Competency Questions and Answers
Mahmoud Moghtaderi
 
PDF
algorithms-16-00088-v2hghjjnjnhhhnnjhj.pdf
Ajaykumar966781
 
PDF
Structs to JSON How Go Powers REST APIs.pdf
Emily Achieng
 
PDF
Cryptography and Information :Security Fundamentals
Dr. Madhuri Jawale
 
PDF
오픈소스 LLM, vLLM으로 Production까지 (Instruct.KR Summer Meetup, 2025)
Hyogeun Oh
 
PPTX
TE-AI-Unit VI notes using planning model
swatigaikwad6389
 
PPTX
Azure-DevOps-Training presentation downloadable
NamanGoyal428595
 
PDF
Introduction to Data Science: data science process
ShivarkarSandip
 
PDF
Monitoring Global Terrestrial Surface Water Height using Remote Sensing - ARS...
VICTOR MAESTRE RAMIREZ
 
PPTX
Ship’s Structural Components.pptx 7.7 Mb
abdalwhab7327
 
PDF
FLEX-LNG-Company-Presentation-Nov-2017.pdf
jbloggzs
 
PDF
dse_final_merit_2025_26 gtgfffffcjjjuuyy
rushabhjain127
 
PPTX
The-Looming-Shadow-How-AI-Poses-Dangers-to-Humanity.pptx
shravanidabhane8
 
PDF
Top 10 read articles In Managing Information Technology.pdf
IJMIT JOURNAL
 
PDF
Unit I Part II.pdf : Security Fundamentals
Dr. Madhuri Jawale
 
PDF
2010_Book_EnvironmentalBioengineering (1).pdf
EmilianoRodriguezTll
 
PDF
Activated Carbon for Water and Wastewater Treatment_ Integration of Adsorptio...
EmilianoRodriguezTll
 
PDF
flutter Launcher Icons, Splash Screens & Fonts
Ahmed Mohamed
 
Fluid Mechanics, Module 3: Basics of Fluid Mechanics
Dr. Rahul Kumar
 
Lesson 3_Tessellation.pptx finite Mathematics
quakeplayz54
 
ETO & MEO Certificate of Competency Questions and Answers
Mahmoud Moghtaderi
 
algorithms-16-00088-v2hghjjnjnhhhnnjhj.pdf
Ajaykumar966781
 
Structs to JSON How Go Powers REST APIs.pdf
Emily Achieng
 
Cryptography and Information :Security Fundamentals
Dr. Madhuri Jawale
 
오픈소스 LLM, vLLM으로 Production까지 (Instruct.KR Summer Meetup, 2025)
Hyogeun Oh
 
TE-AI-Unit VI notes using planning model
swatigaikwad6389
 
Azure-DevOps-Training presentation downloadable
NamanGoyal428595
 
Introduction to Data Science: data science process
ShivarkarSandip
 
Monitoring Global Terrestrial Surface Water Height using Remote Sensing - ARS...
VICTOR MAESTRE RAMIREZ
 
Ship’s Structural Components.pptx 7.7 Mb
abdalwhab7327
 
FLEX-LNG-Company-Presentation-Nov-2017.pdf
jbloggzs
 
dse_final_merit_2025_26 gtgfffffcjjjuuyy
rushabhjain127
 
The-Looming-Shadow-How-AI-Poses-Dangers-to-Humanity.pptx
shravanidabhane8
 
Top 10 read articles In Managing Information Technology.pdf
IJMIT JOURNAL
 
Unit I Part II.pdf : Security Fundamentals
Dr. Madhuri Jawale
 
2010_Book_EnvironmentalBioengineering (1).pdf
EmilianoRodriguezTll
 
Activated Carbon for Water and Wastewater Treatment_ Integration of Adsorptio...
EmilianoRodriguezTll
 
flutter Launcher Icons, Splash Screens & Fonts
Ahmed Mohamed
 

JAVA APPLET BASICS

  • 2. Introduction to Java Applet Programs • Applications are stand alone programs – executed with Java interpreter • Applet is a small program – can be placed on a web page – will be executed by the web browser – give web pages “dynamic content” 2
  • 3. Java Applets • Built using one of general definitions of applets – Applet class – JAapplet class • Java applets are usually graphical – Draw graphics in a defined screen area – Enable user interaction with GUI elements 3
  • 4. Java Applet Classes • Abstract Windowing Toolkit AWT – Earlier versions of Java – Applet class is one of the AWT components • Java Foundation Classes JFC – Extension to Java in 1997 – Has a collection of Swing components for enhanced GUIs – Swing component classes begin with J 4
  • 5. Java Applets • Applets are Java programs that can be embedded in HTML documents – To run an applet you must create a .html file which references the applet – Ready to Program also will run an applet • When browser loads Web page containing applet – Applet downloads into Web browser – begins execution • Can be tested using appletviewer program 5
  • 6. Contrast Application with Applet Application Applet •Object class extended •Class not declared public •Has a main() •static keyword used •Uses System.exit(1) •JApplet class extended •class declared to be public •init() instead of main() •init() not declared with static keyword 6
  • 7. Applet Declaration • Syntax (note difference from application declaration) public class ClassName extends JAapplet 7 ClassName is an object that will be a subclass of JApplet
  • 8. Body of an Applet • Note there is no main() method in an applet – JApplet class provides other methods instead of a main method • First method executed is the init() method 8
  • 9. Applets • Applet – Program that runs in • appletviewer (test utility for applets) • Web browser (IE, Communicator) – Executes when HTML (Hypertext Markup Language) document containing applet is opened – Applications run in command windows • Notes – Focus on fundamental programming concepts first • Explanations will come later 9
  • 10. Applets and Web Pages – HTML • Applets embedded in a web page – Executed when web page loaded by browser • Web pages structured with HTML codes –HyperText Mark-up Language • Syntax <command> . . . </command> 10 Turns format onTurns format on Turns the format offTurns the format off
  • 11. Applets and Web Pages – HTML • Embedding Java applets – Insert applet tags <APPLET> </APPLET> • Call the specific applet by its file name <APPLET CODE = "Whatever.class" WIDTH = nnn HEIGHT = mmmm> <APPLET> Where nnn and mmm are specific pixel sizes 11
  • 12. Applets and Web Pages – HTML • Create the web page code using a text editor • Save it with an .html suffix • Open this file with appletviewer or with a web browser that supports Java • Java Plug-in must be installed (part of J2SDK 1.4.1 from Sun) 12 <HTML> <HEAD> </HEAD> <BODY> <APPLET CODE = . . . > </APPLET> </BODY> </HTML>
  • 13. Applets and Web Pages – HTML • Client Web browser anywhere can access this web page from its host server • Embedded Java applet runs on client browser (of any type platform) • This means a client anywhere on any type of platform can run a piece of software developed on any other type of platform 13 Platform Independence
  • 14. Thinking About Objects • Java an object-oriented language – However, Java has constructs from structured programming • Object orientation – Natural way to think about world and writing computer programs • Object-oriented programming models the real world – Attributes - properties of objects • Size, shape, color, weight, etc. – Behaviors - actions that objects can perform • A ball rolls, bounces, inflates and deflates 14
  • 15. Thinking About Objects • Object orientation (continued) – Inheritance • New classes of objects absorb characteristics of existing classes – Information hiding • Objects usually do not know how other objects are implemented • We can drive cars without knowing how every part works internally 15
  • 16. Thinking About Objects Class - unit of Java programming • Java focuses on nouns (classes) – C focuses on verbs and is action oriented • Contain methods – Implement behaviors • Contain data – Implement attributes • Classes are reusable – Standardized, interchangeable parts 16
  • 17. A Simple Java Applet: Drawing a String • Figure 3.6 – a welcome message applet • The .html code to run the applet in a browser • The program output shown in the Applet Viewer 17 <html> <applet code = "WelcomeApplet.class" width = "300" height = "45"> </applet> </html> <html> <applet code = "WelcomeApplet.class" width = "300" height = "45"> </applet> </html>
  • 18. Running the Applet • Compile – Use Ready to Program – If no errors, bytecodes stored in WelcomeApplet.class • We must create an HTML file – Loads the applet into appletviewer or a browser – Ends in .htm or .html • To execute an applet – Create an HTML file indicating which applet the browser (or appletviewer) should load and execute 18
  • 19. Running the Applet - Alternatively • Run from within Ready to Program • Prompt for applet window size appears • Applet window runs 19
  • 20. 20 import allows us to use predefined classes (allowing us to use applets and graphics, in this case). extends allows us to inherit the capabilities of class JApplet. Method paint is guaranteed to be called in all applets. Its first line must be defined as above.
  • 21. Running An Applet import java.applet.Applet; import java.awt.Graphics; public class HelloApplet extends Applet { public void paint (Graphics g) { g.drawString ("Hello. Welcome to",25,25); g.drawString ("Java Programming",25,40); } } import java.applet.Applet; import java.awt.Graphics; public class HelloApplet extends Applet { public void paint (Graphics g) { g.drawString ("Hello. Welcome to",25,25); g.drawString ("Java Programming",25,40); } } 21 • Enter this text into your Ready to Program editor • Compile the Java code • Enter this text into your Ready to Program editor • Compile the Java code
  • 22. Running An Applet • Now create an .html file to run the applet • Save it as HelloApplet.html • Make sure you save it in the same directory as the .java file 22 <html> <applet code = "HelloApplet.class" width=275, height = 100> </applet> </html> <html> <applet code = "HelloApplet.class" width=275, height = 100> </applet> </html>