Java 1
Java 1
Chittaranjan Pradhan
Chittaranjan Pradhan
School of Computer Engineering,
KIIT University
14.1
Applet
Applet
Chittaranjan Pradhan
Applet
Applet
• Applets are small applications that are accessed on an <APPLET> Tag
main().In fact, most applets don’t even have a main() Applet Lifecycle
Applet Display Methods
method Requesting Repainting
Status Window
• An applet begins execution when the name of its class is Parameter passing to
Applet
• Compile the source code in the same way that you have
been compiling programs
• java.lang.Object → java.awt.Component →
java.awt.Container → java.awt.Panel → java.applet.Applet
• An applet’s class must be public
• Running of applet involves different process:
• Executing the applet within a Java-compatible Web browser
• Using an applet viewer, such as the standard SDK tool,
appletviewer. An appletviewer executes your applet in a
window. This is generally the fastest and easiest way to test
your applet
14.3
Applet
Applet...
Chittaranjan Pradhan
Executing an applet in a Web browser
Applet
• Here, you need to write a short HTML text file that <APPLET> Tag
Applet Class
contains the appropriate APPLET tag Applet Architecture
Applet Lifecycle
Applet Display Methods
Requesting Repainting
Status Window
Parameter passing to
Applet
• After you create this file, you can execute your browser getDocumentBase() and
getCodeBase()
and then load this file, which causes SimpleApplet to be
executed
14.4
Applet
Applet...
Chittaranjan Pradhan
Executing an applet using appletviewer
Applet
• Include a comment at the head of your Java source code <APPLET> Tag
Applet Class
file that contains the APPLET tag Applet Architecture
Applet Lifecycle
Applet Display Methods
Requesting Repainting
Status Window
Parameter passing to
Applet
getDocumentBase() and
getCodeBase()
14.5
Applet
<APPLET> Tag
Chittaranjan Pradhan
Applet
<APPLET> Tag
Applet Class
Applet Architecture
Applet Lifecycle
14.6
Applet
Applet Class
Chittaranjan Pradhan
Applet Class
Applet
<APPLET> Tag
Applet Class
Applet Architecture
Applet Lifecycle
Applet Display Methods
Requesting Repainting
Status Window
Parameter passing to
Applet
getDocumentBase() and
getCodeBase()
14.7
Applet
Applet Architecture
Chittaranjan Pradhan
Applet
occurs. The runtime system notifies the applet about an Requesting Repainting
Status Window
event by calling an event handler that has been provided Parameter passing to
Applet
by the applet. Once this happens, the applet must take getDocumentBase() and
getCodeBase()
14.8
Applet
Applet Lifecycle
Chittaranjan Pradhan
14.9
Applet
Applet Lifecycle...
Chittaranjan Pradhan
Applet Lifecycle...
Applet
<APPLET> Tag
When an applet is terminated, the following sequence of Applet Class
• public void stop(): it is used to stop the Applet. It is Applet Display Methods
Requesting Repainting
14.10
Applet
Applet Lifecycle...
Chittaranjan Pradhan
Applet
<APPLET> Tag
Applet Lifecycle... Applet Class
Applet Architecture
Applet Lifecycle
Applet Display Methods
Requesting Repainting
Status Window
Parameter passing to
Applet
getDocumentBase() and
getCodeBase()
14.11
Applet
Applet Display Methods
Chittaranjan Pradhan
Applet Display Methods
Applet
• The drawString() method will not recognize newline <APPLET> Tag
Applet Class
characters Applet Architecture
Applet Lifecycle
• setBackground() and setForeground() used to set the Applet Display Methods
Applet
<APPLET> Tag
Applet Class
Applet Architecture
Applet Lifecycle
Applet Display Methods
Requesting Repainting
Status Window
Parameter passing to
Applet
getDocumentBase() and
getCodeBase()
14.13
Applet
Example 2
Chittaranjan Pradhan
Applet
<APPLET> Tag
Applet Class
Applet Architecture
Applet Lifecycle
Applet Display Methods
Requesting Repainting
Status Window
Parameter passing to
Applet
getDocumentBase() and
getCodeBase()
14.14
Applet
Requesting Repainting
Chittaranjan Pradhan
Requesting Repainting
Applet
<APPLET> Tag
• As a general rule, an applet writes to its window only when Applet Class
14.15
Applet
Status Window
Chittaranjan Pradhan
Status Window
An applet can also output a message to the status window of Applet
<APPLET> Tag
the browser or applet viewer on which it is running by using Applet Class
14.16
Applet
Parameter passing to Applet
Chittaranjan Pradhan
APPLET tag allows to pass parameters to the applet
Applet
<APPLET> Tag
Applet Class
Applet Architecture
Applet Lifecycle
Applet Display Methods
Requesting Repainting
Status Window
Parameter passing to
Applet
getDocumentBase() and
getCodeBase()
14.17
Applet
getDocumentBase() and getCodeBase()
Chittaranjan Pradhan
getDocumentBase() and getCodeBase()
DocumentBase gives the detailed path of the applet’s class file. Applet
<APPLET> Tag
CodeBase gives the directory from which the applet’s class file Applet Class
Applet Architecture
was loaded Applet Lifecycle
Applet Display Methods
Requesting Repainting
Status Window
Parameter passing to
Applet
getDocumentBase() and
getCodeBase()
14.18