SlideShare una empresa de Scribd logo
1 de 6
Descargar para leer sin conexión
Core Java

Debasish Pratihari

Applet:


Applets are small applications that are accessed
on an internet server, transposed over the
internet, automatically installed, and run as part
of a web component.



Applets are Java programs that are embedded
within a Web page. Therefore, unlike
applications, applets require a Java-enabled
browser, such as Microsoft Internet Explorer 4.0
or later, Netscape Navigator 4.0 or later, or
HotJava. These browsers are said to be Javaenabled because they have a built-in Java
platform (JVM and Java API).



An applet is loaded and executed when you load
a Web page by using a Web browser. When a
Web page containing an applet is displayed, you
can interact with the applet. You can use applets
to add dynamic features, such as animation and
sound, to a Web page. You can also use them to
make a Web page interactive.



After an applet arrives on the client, it has
limited access to resources, so that it can
produce a reliable user interface without
introducing the risk of viruses.

More About Applet :









Are sub-classes of Applet Class
<applet> tag of html is used to load an
applet in a web page.
Are executed remotely by java-enabled
browser.
Do not have a main( ) method.
Execution begins at init( ) method
Are not independent objects like application
Are purely GUI.
It can access the resources of only the host
computer; it cannot access the files on the
computer on which it is downloaded.

Lecture/core/applet/22

Page #1

feel the Technology…
Core Java

Debasish Pratihari

The life cycle of an Applet :



init()

is executed only once



start()

Executed multiple times every time
the focus comes backs to the page



stop()

Executed multiple times every time
The focus is lost from the web Page.



destroy()

Is called only once when the page is
terminated or closed.



An applet writes to its window only when its update() or
paint() method is called by the AWT.



The fundamental architecture constraints imposed on an
applet is that it must quickly return control to the AWT
run-time system. So you shouldn’t create a loop in
side paint().



The repaint() method is defined by the AWT. It causes
the AWT run-time system to execute a call to your
applet’s update( ) method, which in its default
implementation, calls paint ( ).



The paint() method Called every time the window is
resized or restored or Called forcibly by the user by calling
repaint( ) method

Lecture/core/applet/22

Page #2

feel the Technology…
Core Java

Debasish Pratihari

Creating an Applet:
import java.awt.*
import java.appet.*
sub-class the applet class
over-ride methods as per need.
Save the file with extension .java
Compile to create .class file
Create a HTML file
Use applet tag to position the applet inside the
page
 <applet code = x width =300 height=200>
</applet>
 save the file with extension .html
 open a browser and load the .html file









Attributes of Applet Tag:
code

:

specifies the applet class file

[codebase]

:

is an optional attribute that specifies the base
URL of the Applet.

height

:

specifies the height of applet

width

:

specifies width of applet

[align]

:

specifies alignment, the align must constant are
LEFT, RIGHT, TEXTTOP, MIDDLE, ABSMIDDLE,
BOTTOM, ABSBOTTOM, BASELINE

[vspace]

:

specifies vertical space

[Hspace]

:

specifies horizontal space

[archieve]

:

specifies the jar file

[Name]

:

specifies the alias name for the applet used
for inter applet communication.

Example :
import java.awt.*;
import java.applet.*;
/*<applet code = myapplet width=300 height=400></applet>*/

public class Myapplet extends Applet{
public void paint(Graphics g){
g.drawString(“ hello every body”,10,20);
}
}

Lecture/core/applet/22

Page #3

Note :
You can test Applets
using the Java Tool
appletviewer.

feel the Technology…
Core Java

Debasish Pratihari

A summary of Methods in the Applet Package:
Method

Function

public String getAppletInfo()
public URL getDocumentBase()
public String
getParameter(String name)
public String [][]
getParameterInfo()
public AudioClip
getAudioClip(URL)

Returns information about
the applet, such as author
Returns the URL of the
HTML document
Returns the parameters for
an applet
Returns a summary of what
the parameters control
Used to load an audio clip

public Image getImage(URL)

Used to load an image file
Used to play a previously
loaded audio clip
Lets you know whether an
applet is active

public void play(URL)
public boolean isActive()
public void resize(int, int)

Used to resize the applet

public void showStatus(String
msg)

Displays a status string in
the applet's browser

public void init()

Initializes the applet
Starts the applet when it's
finished initializing
Stops the applet when you
leave the applet's page
Destroys the applet when
you leave the browser

public void start()
public void stop()
public void destroy()

Difference between Application & Applet :
Application

Applet

Are independent

Dependent

Are executed under the local
o/s.

Executed remotely by a browser.

CUI or GUI

GUI

Execution starts with main( )

Starts with init(

Terminates with main()

Terminates only when the page is
closed

Lecture/core/applet/22

Page #4

) method.

feel the Technology…
Core Java

Debasish Pratihari

Notes
The Graphics Class
The Graphics class is an abstract class that represents the display area of an applet. This class is
a part of the java.awt package and you use it to draw images within the display area of the
applet. The object of the Graphics class is used for painting the applet.
The init() Method
The init() method is called when an applet is loaded into the memory of a computer for the first
time. The init() method works like a constructor, which means that it is executed automatically
by the system. By using the init() method, you can initialize variables and add components such
as buttons and check boxes to an applet.
The start() Method
The start() method is called immediately after the init() method is called and is executed each
time you visit other pages and return to the page containing the applet. You can use this method
when you want to restart a process each time a user visits a page. For example, you can use the
start() method in situations where you want to restart an animation sequence or a thread for
your applet. If your applet does not execute any statements when a user exits from the current
Web page, you need not implement this method.
The stop() Method
The stop() method is called each time an applet loses its focus. For example, when a user exits
out of the page on which the applet is loaded, the stop() method is called. You can use this
method to reset variables and stop the threads that are running. This method gives you a chance
to stop activities that slow down the computer.
The destroy() Method
The destroy() method is called when you start viewing another Web page. You can use this
method to perform clean-up operations, such as closing a file. Java calls the stop() method
before calling the destroy() method.
The update() Method
The update() method takes the Graphics class object as a parameter. When the applet area
needs to be redrawn, the Windows system starts the painting process. The update() method is
called to clear the screen and it in turn calls the paint() method. The system then updates the
screen.
The paint() Method
The paint() method draws the graphics of an applet in the drawing area. The method is
automatically called when an applet is displayed on the screen for the first time and each time
the applet receives focus. The paint() method can be triggered by invoking the repaint() method.
The paint() method of an applet takes an object of the Graphics class as a parameter.
The repaint() Method
You can call the repaint() method when you want to redraw an applet area. The repaint() method
calls the update() method to signal that an applet has to be updated. The default action of the
update() method is to clear the applet area and call the paint() method. You can override the
update() method if you do not want the applet area to be cleared.

Lecture/core/applet/22

Page #5

feel the Technology…
Core Java

Debasish Pratihari

getDocumentBase()
Although the getDocumentBase() method simply returns the URL of the document your applet is
embedded in, this URL comes in very handy with other methods. For example, the methods
discussed in the next two sections take a URL as one of their arguments. Instead of hard coding
a URL, you can use the getDocumentBase() method to pass the URL to any methods that require
a URL, such as getAudioClip() and getImage(), as in the following example:
graphic = getParameter("graphic");
clip = getParameter("clip");
image = getImage(getDocumentBase(), graphic);
sound = getAudioClip(getDocumentBase(), clip);
getAudioClip(URL, String)
The getAudioClip() method accepts a URL, which specifies the location of sound files on the
server, and a string to represent the name of the file. Keep in mind that you can use the
getDocumentBase() method to provide the URL, so if you move your applet, you don't have to
recode the getAudioClip() method. If you wanted to load an audio file called soundfile.au, you
could use the following code:
AudioClip clip;
clip = getAudioClip(getDocumentBase(), "soundfile.au");
This code just defines a variable called clip for the audio file and then makes clip equal to the
result of the getAudioClip() method. The getAudioClip() method uses the getDocumentBase()
method to supply the URL, and then you give the getAudioClip() method the name of the sound
file directly. You could also use a variable for the name of the sound file, which would make the
filename a little more flexible.
Audio methods are contained with the Applet Package within the AudioClip interface. An interface
is a specification the ensures that certain methods will be defined for a class. For example, the
AudioClip interface ensures that the getAudioClip(), play(), and loop() methods will be defined.
Table 10.2 summarizes the available audio methods.
Audio methods.
Method

Function

getAudioClip()

Loads an audio file from the server

play()

Plays the audio file once through

loop()

Plays the audio file in a continuous loop

stop()

Stops a play() or loop() method that is in progress

Lecture/core/applet/22

Page #6

feel the Technology…

Más contenido relacionado

La actualidad más candente (20)

Java Applet and Graphics
Java Applet and GraphicsJava Applet and Graphics
Java Applet and Graphics
 
first-applet
first-appletfirst-applet
first-applet
 
Applet
AppletApplet
Applet
 
java Unit4 chapter1 applets
java Unit4 chapter1 appletsjava Unit4 chapter1 applets
java Unit4 chapter1 applets
 
Java applets
Java appletsJava applets
Java applets
 
Applet and graphics programming
Applet and graphics programmingApplet and graphics programming
Applet and graphics programming
 
java applets
java appletsjava applets
java applets
 
Applet life cycle
Applet life cycleApplet life cycle
Applet life cycle
 
Applet
 Applet Applet
Applet
 
27 applet programming
27  applet programming27  applet programming
27 applet programming
 
Client Side Programming with Applet
Client Side Programming with AppletClient Side Programming with Applet
Client Side Programming with Applet
 
Oop suplemnertary september 2019
Oop suplemnertary september  2019Oop suplemnertary september  2019
Oop suplemnertary september 2019
 
Applet (1)
Applet (1)Applet (1)
Applet (1)
 
Java Applet
Java AppletJava Applet
Java Applet
 
Applet programming
Applet programming Applet programming
Applet programming
 
6.applet programming in java
6.applet programming in java6.applet programming in java
6.applet programming in java
 
Awt, Swing, Layout managers
Awt, Swing, Layout managersAwt, Swing, Layout managers
Awt, Swing, Layout managers
 
Java applets
Java appletsJava applets
Java applets
 
Applets
AppletsApplets
Applets
 
Java Applets
Java AppletsJava Applets
Java Applets
 

Destacado

Reviewing Screen Based Content: Demo Examples
Reviewing Screen Based Content: Demo ExamplesReviewing Screen Based Content: Demo Examples
Reviewing Screen Based Content: Demo ExamplesRhonda Bracey
 
Pelajaran 2 Bm
Pelajaran 2 BmPelajaran 2 Bm
Pelajaran 2 Bmamoi286
 
Niver Paula - 28.11.07
Niver Paula - 28.11.07Niver Paula - 28.11.07
Niver Paula - 28.11.07Jubrac Jacui
 
Niver Erica E Marcos - 22.10.07
Niver Erica E Marcos - 22.10.07Niver Erica E Marcos - 22.10.07
Niver Erica E Marcos - 22.10.07Jubrac Jacui
 
2010 Fashion Show Booklet Revise
2010 Fashion Show Booklet Revise2010 Fashion Show Booklet Revise
2010 Fashion Show Booklet ReviseNg Lim
 
Delphi Scalper Review | Delphi Scalper Bonus
Delphi Scalper Review | Delphi Scalper BonusDelphi Scalper Review | Delphi Scalper Bonus
Delphi Scalper Review | Delphi Scalper BonusCoty Schwabe
 
Battle of luoisbourg keynote0
Battle of luoisbourg keynote0Battle of luoisbourg keynote0
Battle of luoisbourg keynote0iamcanehdian
 
A History Of Salento Colombia
A History Of Salento ColombiaA History Of Salento Colombia
A History Of Salento ColombiaSergio Pino
 
18.05.08 Acaosocial
18.05.08   Acaosocial18.05.08   Acaosocial
18.05.08 AcaosocialJubrac Jacui
 
Webbit 2004: Tiger, java
Webbit 2004: Tiger, javaWebbit 2004: Tiger, java
Webbit 2004: Tiger, javaMatteo Baccan
 
Dagaz Solutions Company Presentation
Dagaz Solutions Company PresentationDagaz Solutions Company Presentation
Dagaz Solutions Company PresentationDoug de Urioste
 

Destacado (20)

Microcamp
MicrocampMicrocamp
Microcamp
 
Reviewing Screen Based Content: Demo Examples
Reviewing Screen Based Content: Demo ExamplesReviewing Screen Based Content: Demo Examples
Reviewing Screen Based Content: Demo Examples
 
Graffiti
GraffitiGraffiti
Graffiti
 
網路行銷
網路行銷網路行銷
網路行銷
 
Pelajaran 2 Bm
Pelajaran 2 BmPelajaran 2 Bm
Pelajaran 2 Bm
 
Have You Ever Noticed
Have You Ever NoticedHave You Ever Noticed
Have You Ever Noticed
 
Hazel and Kate-Unison
Hazel and Kate-UnisonHazel and Kate-Unison
Hazel and Kate-Unison
 
111219 outsourcing
111219 outsourcing111219 outsourcing
111219 outsourcing
 
Presentatie avans1
Presentatie avans1Presentatie avans1
Presentatie avans1
 
Tema ii
Tema iiTema ii
Tema ii
 
Niver Paula - 28.11.07
Niver Paula - 28.11.07Niver Paula - 28.11.07
Niver Paula - 28.11.07
 
Niver Erica E Marcos - 22.10.07
Niver Erica E Marcos - 22.10.07Niver Erica E Marcos - 22.10.07
Niver Erica E Marcos - 22.10.07
 
2010 Fashion Show Booklet Revise
2010 Fashion Show Booklet Revise2010 Fashion Show Booklet Revise
2010 Fashion Show Booklet Revise
 
Delphi Scalper Review | Delphi Scalper Bonus
Delphi Scalper Review | Delphi Scalper BonusDelphi Scalper Review | Delphi Scalper Bonus
Delphi Scalper Review | Delphi Scalper Bonus
 
Battle of luoisbourg keynote0
Battle of luoisbourg keynote0Battle of luoisbourg keynote0
Battle of luoisbourg keynote0
 
A History Of Salento Colombia
A History Of Salento ColombiaA History Of Salento Colombia
A History Of Salento Colombia
 
18.05.08 Acaosocial
18.05.08   Acaosocial18.05.08   Acaosocial
18.05.08 Acaosocial
 
La Mujer Ideal
La Mujer IdealLa Mujer Ideal
La Mujer Ideal
 
Webbit 2004: Tiger, java
Webbit 2004: Tiger, javaWebbit 2004: Tiger, java
Webbit 2004: Tiger, java
 
Dagaz Solutions Company Presentation
Dagaz Solutions Company PresentationDagaz Solutions Company Presentation
Dagaz Solutions Company Presentation
 

Similar a Core Java Applet Guide

Similar a Core Java Applet Guide (20)

Smart material - Unit 3 (2).pdf
Smart material - Unit 3 (2).pdfSmart material - Unit 3 (2).pdf
Smart material - Unit 3 (2).pdf
 
Smart material - Unit 3 (1).pdf
Smart material - Unit 3 (1).pdfSmart material - Unit 3 (1).pdf
Smart material - Unit 3 (1).pdf
 
Appletjava
AppletjavaAppletjava
Appletjava
 
Applets
AppletsApplets
Applets
 
Java applet basics
Java applet basicsJava applet basics
Java applet basics
 
oops with java modules iii & iv.pptx
oops with java modules iii & iv.pptxoops with java modules iii & iv.pptx
oops with java modules iii & iv.pptx
 
Applet and graphics programming
Applet and graphics programmingApplet and graphics programming
Applet and graphics programming
 
Applet in java new
Applet in java newApplet in java new
Applet in java new
 
Java files and io streams
Java files and io streamsJava files and io streams
Java files and io streams
 
Unit 7 Java
Unit 7 JavaUnit 7 Java
Unit 7 Java
 
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
 
Java
JavaJava
Java
 
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
 
Applets in Java
Applets in JavaApplets in Java
Applets in Java
 
Applet.pptx
Applet.pptxApplet.pptx
Applet.pptx
 
Applets
AppletsApplets
Applets
 
Java applet
Java appletJava applet
Java applet
 
6applets And Graphics
6applets And Graphics6applets And Graphics
6applets And Graphics
 
applet.pptx
applet.pptxapplet.pptx
applet.pptx
 
Java applet-basics
Java applet-basicsJava applet-basics
Java applet-basics
 

Más de Debasish Pratihari (20)

Lecture 24
Lecture 24Lecture 24
Lecture 24
 
Lecture 23
Lecture 23Lecture 23
Lecture 23
 
Lecture 21
Lecture 21Lecture 21
Lecture 21
 
Lecture 20
Lecture 20Lecture 20
Lecture 20
 
Lecture 19
Lecture 19Lecture 19
Lecture 19
 
Lecture 18
Lecture 18Lecture 18
Lecture 18
 
Lecture 17
Lecture 17Lecture 17
Lecture 17
 
Lecture 16
Lecture 16Lecture 16
Lecture 16
 
Lecture 14
Lecture 14Lecture 14
Lecture 14
 
Lecture 10
Lecture 10Lecture 10
Lecture 10
 
Lecture 9
Lecture 9Lecture 9
Lecture 9
 
Lecture 8
Lecture 8Lecture 8
Lecture 8
 
Lecture 7
Lecture 7Lecture 7
Lecture 7
 
Lecture 6
Lecture 6Lecture 6
Lecture 6
 
Lecture 5
Lecture 5Lecture 5
Lecture 5
 
Lecture 4
Lecture 4Lecture 4
Lecture 4
 
Lecture 3
Lecture 3Lecture 3
Lecture 3
 
Lecture 2
Lecture 2Lecture 2
Lecture 2
 
Lecture 1
Lecture 1Lecture 1
Lecture 1
 
Lecture25
Lecture25Lecture25
Lecture25
 

Último

Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 

Último (20)

Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 

Core Java Applet Guide

  • 1. Core Java Debasish Pratihari Applet:  Applets are small applications that are accessed on an internet server, transposed over the internet, automatically installed, and run as part of a web component.  Applets are Java programs that are embedded within a Web page. Therefore, unlike applications, applets require a Java-enabled browser, such as Microsoft Internet Explorer 4.0 or later, Netscape Navigator 4.0 or later, or HotJava. These browsers are said to be Javaenabled because they have a built-in Java platform (JVM and Java API).  An applet is loaded and executed when you load a Web page by using a Web browser. When a Web page containing an applet is displayed, you can interact with the applet. You can use applets to add dynamic features, such as animation and sound, to a Web page. You can also use them to make a Web page interactive.  After an applet arrives on the client, it has limited access to resources, so that it can produce a reliable user interface without introducing the risk of viruses. More About Applet :         Are sub-classes of Applet Class <applet> tag of html is used to load an applet in a web page. Are executed remotely by java-enabled browser. Do not have a main( ) method. Execution begins at init( ) method Are not independent objects like application Are purely GUI. It can access the resources of only the host computer; it cannot access the files on the computer on which it is downloaded. Lecture/core/applet/22 Page #1 feel the Technology…
  • 2. Core Java Debasish Pratihari The life cycle of an Applet :  init() is executed only once  start() Executed multiple times every time the focus comes backs to the page  stop() Executed multiple times every time The focus is lost from the web Page.  destroy() Is called only once when the page is terminated or closed.  An applet writes to its window only when its update() or paint() method is called by the AWT.  The fundamental architecture constraints imposed on an applet is that it must quickly return control to the AWT run-time system. So you shouldn’t create a loop in side paint().  The repaint() method is defined by the AWT. It causes the AWT run-time system to execute a call to your applet’s update( ) method, which in its default implementation, calls paint ( ).  The paint() method Called every time the window is resized or restored or Called forcibly by the user by calling repaint( ) method Lecture/core/applet/22 Page #2 feel the Technology…
  • 3. Core Java Debasish Pratihari Creating an Applet: import java.awt.* import java.appet.* sub-class the applet class over-ride methods as per need. Save the file with extension .java Compile to create .class file Create a HTML file Use applet tag to position the applet inside the page  <applet code = x width =300 height=200> </applet>  save the file with extension .html  open a browser and load the .html file         Attributes of Applet Tag: code : specifies the applet class file [codebase] : is an optional attribute that specifies the base URL of the Applet. height : specifies the height of applet width : specifies width of applet [align] : specifies alignment, the align must constant are LEFT, RIGHT, TEXTTOP, MIDDLE, ABSMIDDLE, BOTTOM, ABSBOTTOM, BASELINE [vspace] : specifies vertical space [Hspace] : specifies horizontal space [archieve] : specifies the jar file [Name] : specifies the alias name for the applet used for inter applet communication. Example : import java.awt.*; import java.applet.*; /*<applet code = myapplet width=300 height=400></applet>*/ public class Myapplet extends Applet{ public void paint(Graphics g){ g.drawString(“ hello every body”,10,20); } } Lecture/core/applet/22 Page #3 Note : You can test Applets using the Java Tool appletviewer. feel the Technology…
  • 4. Core Java Debasish Pratihari A summary of Methods in the Applet Package: Method Function public String getAppletInfo() public URL getDocumentBase() public String getParameter(String name) public String [][] getParameterInfo() public AudioClip getAudioClip(URL) Returns information about the applet, such as author Returns the URL of the HTML document Returns the parameters for an applet Returns a summary of what the parameters control Used to load an audio clip public Image getImage(URL) Used to load an image file Used to play a previously loaded audio clip Lets you know whether an applet is active public void play(URL) public boolean isActive() public void resize(int, int) Used to resize the applet public void showStatus(String msg) Displays a status string in the applet's browser public void init() Initializes the applet Starts the applet when it's finished initializing Stops the applet when you leave the applet's page Destroys the applet when you leave the browser public void start() public void stop() public void destroy() Difference between Application & Applet : Application Applet Are independent Dependent Are executed under the local o/s. Executed remotely by a browser. CUI or GUI GUI Execution starts with main( ) Starts with init( Terminates with main() Terminates only when the page is closed Lecture/core/applet/22 Page #4 ) method. feel the Technology…
  • 5. Core Java Debasish Pratihari Notes The Graphics Class The Graphics class is an abstract class that represents the display area of an applet. This class is a part of the java.awt package and you use it to draw images within the display area of the applet. The object of the Graphics class is used for painting the applet. The init() Method The init() method is called when an applet is loaded into the memory of a computer for the first time. The init() method works like a constructor, which means that it is executed automatically by the system. By using the init() method, you can initialize variables and add components such as buttons and check boxes to an applet. The start() Method The start() method is called immediately after the init() method is called and is executed each time you visit other pages and return to the page containing the applet. You can use this method when you want to restart a process each time a user visits a page. For example, you can use the start() method in situations where you want to restart an animation sequence or a thread for your applet. If your applet does not execute any statements when a user exits from the current Web page, you need not implement this method. The stop() Method The stop() method is called each time an applet loses its focus. For example, when a user exits out of the page on which the applet is loaded, the stop() method is called. You can use this method to reset variables and stop the threads that are running. This method gives you a chance to stop activities that slow down the computer. The destroy() Method The destroy() method is called when you start viewing another Web page. You can use this method to perform clean-up operations, such as closing a file. Java calls the stop() method before calling the destroy() method. The update() Method The update() method takes the Graphics class object as a parameter. When the applet area needs to be redrawn, the Windows system starts the painting process. The update() method is called to clear the screen and it in turn calls the paint() method. The system then updates the screen. The paint() Method The paint() method draws the graphics of an applet in the drawing area. The method is automatically called when an applet is displayed on the screen for the first time and each time the applet receives focus. The paint() method can be triggered by invoking the repaint() method. The paint() method of an applet takes an object of the Graphics class as a parameter. The repaint() Method You can call the repaint() method when you want to redraw an applet area. The repaint() method calls the update() method to signal that an applet has to be updated. The default action of the update() method is to clear the applet area and call the paint() method. You can override the update() method if you do not want the applet area to be cleared. Lecture/core/applet/22 Page #5 feel the Technology…
  • 6. Core Java Debasish Pratihari getDocumentBase() Although the getDocumentBase() method simply returns the URL of the document your applet is embedded in, this URL comes in very handy with other methods. For example, the methods discussed in the next two sections take a URL as one of their arguments. Instead of hard coding a URL, you can use the getDocumentBase() method to pass the URL to any methods that require a URL, such as getAudioClip() and getImage(), as in the following example: graphic = getParameter("graphic"); clip = getParameter("clip"); image = getImage(getDocumentBase(), graphic); sound = getAudioClip(getDocumentBase(), clip); getAudioClip(URL, String) The getAudioClip() method accepts a URL, which specifies the location of sound files on the server, and a string to represent the name of the file. Keep in mind that you can use the getDocumentBase() method to provide the URL, so if you move your applet, you don't have to recode the getAudioClip() method. If you wanted to load an audio file called soundfile.au, you could use the following code: AudioClip clip; clip = getAudioClip(getDocumentBase(), "soundfile.au"); This code just defines a variable called clip for the audio file and then makes clip equal to the result of the getAudioClip() method. The getAudioClip() method uses the getDocumentBase() method to supply the URL, and then you give the getAudioClip() method the name of the sound file directly. You could also use a variable for the name of the sound file, which would make the filename a little more flexible. Audio methods are contained with the Applet Package within the AudioClip interface. An interface is a specification the ensures that certain methods will be defined for a class. For example, the AudioClip interface ensures that the getAudioClip(), play(), and loop() methods will be defined. Table 10.2 summarizes the available audio methods. Audio methods. Method Function getAudioClip() Loads an audio file from the server play() Plays the audio file once through loop() Plays the audio file in a continuous loop stop() Stops a play() or loop() method that is in progress Lecture/core/applet/22 Page #6 feel the Technology…