SlideShare a Scribd company logo
Programming in JAVA
Topic: Applets
Introduction
• A Java applet is a special kind of Java program that a java-
enabled browser can download from the internet and run.
• An applet is typically embedded inside a web page and runs in
the context of a browser.
• An applet must be a subclass of the java.applet.Applet class.
• The Applet class provides the standard interface between the
applet and the browser environment.
• Applets are not stand-alone programs.
• Instead, they run within either a web browser or an applet viewer.
• Execution of an applet does not begin at main( ).
• Output to applet’s window is not performed by
System.out.println( ).
Types of Applets
• There are two types of applets.
• The first are based directly on the Applet class and use the AWT
to provide the graphic user interface.
• These applets has been available since Java was first created.
• The second type of applets are based on the Swing class
JApplet.
• Swing applets use the Swing classes to provide the GUI.
• Swing offers a richer and often easier-to-use user interface than
does the AWT.
• Swing-based applets are now the most popular. However,
traditional AWT-based applets are still used, especially when
only a very simple user interface is required.
• Thus, both AWT and Swing-based applets are valid.
• Because JApplet inherits Applet, all the features of Applet are
also available in JApplet
Applet Class
• Applet provides all necessary support for applet execution, such
as starting and stopping.
• It also provides methods that load and display images, and
methods that load and play audio clips.
• Applet extends the AWT class Panel. In turn, Panel extends
Container, which extends Component.
Applet Class Hierarchy
Applet Methods called by the system
• public void init()
To initialize the Applet When the applet is first loaded.
• public void start()
Starts applet when the applet is displayed.
Automatically called after init( ) when an applet first begins.
• public void stop()
When the browser leaves the page containing the applet.
• public void destroy()
Called by the browser just before an applet is terminated.
• public void paint(Graphics g)
Applet Initialization and Termination
• When an applet begins, the following methods are called, in this
sequence:
1.init( )
2.start( )
3.paint( )
• When an applet is terminated, the following sequence of
method calls takes place:
1.stop( )
2.destroy( )
init( )
• The init( ) method is the first method to be called.
• This is where we should initialize variables.
• This method is called only once during the run time of your
applet.
start( )
• The start( ) method is called after init( ).
• It is also called to restart an applet after it has been stopped.
• init( )is called once—the first time an applet is loaded whereas
start( ) is called each time an applet’s HTML document is
displayed on screen.
• So, if a user leaves a web page and comes back, the applet
resumes execution at start( ).
paint( )
• The paint( ) method is called each time the applet’s output must be
redrawn.
• This situation can occur for several reasons. For example, the window
in which the applet is running may be overwritten by another window
and then uncovered. Or the applet window may be minimized and
then restored.
• paint( ) is also called when the applet begins execution.
• The paint( ) method has one parameter of type Graphics, which
describes the graphics environment in which the applet is running.
stop( )
• The stop( ) method is called when a web browser leaves the HTML
document containing the applet(e.g. when it goes to another page).
• When stop( )is called, the applet may be running. We can restart them
when start( )is called if the user returns to the page.
destroy( )
• The destroy( ) method is called when the environment
determines that the applet needs to be removed completely from
memory.
• It frees up any resources the applet may be using.
• The stop( ) method is always called before destroy( ).
Applet Life Cycle
Graphics Class
• The Graphics class provides the methods for drawing strings,
lines, rectangles, ovals, arcs, polygons, and polylines.
• void setColor(Color c)
• void setFont(Font f)
• void drawString(String s, int x, int y)
• void drawLine(int x1, int y1, int x2, int y2)
• void drawRect(int x, int y, int w, int h)
• void fillRect(int x, int y, int w, int h)
• void drawRoundRect(int x, int y, int w, int h, int aw, int ah)
• void fillRoundRect(int x, int y, int w, int h, int aw, int ah)
Graphics Methods
• void drawOval(int x, int y, int w, int h)
• void fillOval(int x, int y, int w, int h)
• void drawArc(int x, int y, int w, int h, int start_angle, int
arc_angle)
• void fillArc(int x, int y, int w, int h, int start_angle, int
arc_angle)
• void drawPolygon (int [] x, int [] y, int n_point)
• void fillPolygon (int [] x, int [] y, int n_point)
• void drawPolyline (int [] x, int [] y, int n_point)
Graphics Methods
Color class
• We can set colors for GUI components by using the java.awt.Color
class.
• We can use one of the 13 standard colors (BLACK, BLUE, CYAN,
DARK_GRAY, GRAY, GREEN, LIGHT_GRAY, MAGENTA,
ORANGE, PINK, RED, WHITE, and YELLOW) defined as
constants in java.awt.Color.
• Colors are made of red, green, and blue components, each represented
by an int value that describes its intensity, ranging from 0(lightest
shade) to 255(darkest shade). This is known as the RGB model.
• We can create a color using the following constructor:
public Color(int r, int g, int b);
• Color color = new Color(128,100,100);
• The arguments r, g, b are between 0 and 255. If a value beyond this
range is passed to the argument, an IllegalArgumentException will
occur.
Example:
JButton jb1 = new JButton("OK");
jb1.setBackground(color);
jb1.setForeground (new Color(100,1,1));
Font class
• We can create a font using the java.awt.Font class and set fonts for the
components using the setFont method in the Component class.
• The constructor for Font is:
public Font (String name, int style, int size);
• You can choose a font name from SansSerif, Serif, Monospaced,
Dialog, or DialogInput.
• Choose a style from Font.PLAIN(0), Font.BOLD(1),
Font.ITALIC(2), and Font.BOLD+Font.ITALIC(3), and specify a
font size of any positive integer.
Font class
• Example:
Font font1 = new Font("SansSerif", Font.BOLD, 16);
Font font2 = new Font("Serif", Font.BOLD +
Font.ITALIC, 12);
JButton jbtOK = new JButton("OK");
jbtOK.setFont(font1);
setBackground() & setForeground()
• To set the background color of an applet’s window, we use
setBackground( ).
void setBackground(Color newColor)
• To set the foreground color (the color in which text is shown,
for example), we use setForeground( ).
void setForeground(Color newColor)
• These methods are defined by Component.
• A good place to set the foreground and background colors is in
the init( ) method.
Simple Applet Display Methods
drawString( )
• used to output a string to an applet.
• is a member of the Graphics class.
• called from within either update( ) or paint( ).
void drawString (String message, int x, int y)
• The drawString( ) method will not recognize new line characters.
• If we want to start a line of text on another line, we must do so
manually, specifying the precise X, Y location where we want the line
to begin.
repaint()
• Whenever an applet needs to update the information displayed in its
window, it simply calls repaint( ).
• The repaint( ) method is defined by the AWT.
• It causes the AWT run-time system to execute a call to applet’s
update( ) method, which, in its default implementation, calls paint( ).
void repaint( )
void repaint(int left, int top, int width, int height)
void repaint(long maxDelay)
void repaint(long maxDelay, int x, int y, int width, int height)
Example
import java.awt.*;
import java.applet.*;
/* <applet code="Banner" width=300 height=50> </applet> */
public class Banner extends Applet implements Runnable
{
String msg = " Ravi Kant Sahu ";
Thread t = null;
int state;
boolean stopFlag;
// Set colors and initialize thread.
public void init()
{
setBackground(Color.cyan);
setForeground(Color.red);
}
// Start thread
public void start()
{ t = new Thread(this);
stopFlag = false;
t.start(); }
public void run()
{ char ch;
// Display banner
for( ; ; ) { try {
repaint();
Thread.sleep(450);
ch = msg.charAt(0);
msg = msg.substring(1, msg.length());
msg += ch;
if(stopFlag) break;
}
catch(InterruptedException e) {}
}
}
// Pause the banner.
public void stop()
{
stopFlag = true;
t = null;
}
// Display the banner.
public void paint(Graphics g)
{
g.drawString(msg, 50, 30);
}
}
Status Window in Applets
• An applet can output a message to the status window of the browser
or applet viewer on which it is running.
• showStatus( ) method is used to display the status message.
• The status window is a good place to give the user feedback about
what is occurring in the applet, suggest options, or possibly report
some types of errors.
Example
import java.awt.*;
import java.applet.*;
/* <applet code="StatusWindow" width=300 height=50> </applet> */
public class StatusWindow extends Applet
{
public void init()
{
setBackground(Color.cyan);
}
public void paint(Graphics g)
{
g.drawString("Ravi Kant Sahu", 10, 20);
showStatus("This applet is running on Appletviewer.");
}
}
L18 applets

More Related Content

What's hot

java applets
java appletsjava applets
java applets
Waheed Warraich
 
Applet init nd termination.59
Applet init nd termination.59Applet init nd termination.59
Applet init nd termination.59
myrajendra
 
Applet life cycle
Applet life cycleApplet life cycle
Applet life cycle
myrajendra
 
Java applets
Java appletsJava applets
Java applets
lopjuan
 
Applet programming in java
Applet programming in javaApplet programming in java
Applet programming in java
Vidya Bharti
 
Applet Architecture - Introducing Java Applets
Applet Architecture - Introducing Java AppletsApplet Architecture - Introducing Java Applets
Applet Architecture - Introducing Java Applets
amitksaha
 
Java applet basics
Java applet basicsJava applet basics
Java applet basics
Sunil Pandey
 
java Applet Introduction
java Applet Introductionjava Applet Introduction
java Applet Introduction
yugandhar vadlamudi
 
Java applets
Java appletsJava applets
Java applets
Pihu Goel
 
Java applet - java
Java applet - javaJava applet - java
Java applet - java
Rubaya Mim
 
Applet progming
Applet progmingApplet progming
Applet progming
VIKRANTHMALLIKARJUN
 
6.applet programming in java
6.applet programming in java6.applet programming in java
6.applet programming in java
Deepak Sharma
 
Applet execution
Applet execution Applet execution
Applet execution
myrajendra
 
Java applets
Java appletsJava applets
Java applets
M Vishnuvardhan Reddy
 
Java Applet
Java AppletJava Applet
Java Applet
Athharul Haq
 
Applet in java
Applet in javaApplet in java
Applet in java
Jancypriya M
 
Java applets
Java appletsJava applets
Basics of applets.53
Basics of applets.53Basics of applets.53
Basics of applets.53
myrajendra
 
applet using java
applet using javaapplet using java
applet using java
Kartik Kalpande Patil
 
Applet skelton58
Applet skelton58Applet skelton58
Applet skelton58
myrajendra
 

What's hot (20)

java applets
java appletsjava applets
java applets
 
Applet init nd termination.59
Applet init nd termination.59Applet init nd termination.59
Applet init nd termination.59
 
Applet life cycle
Applet life cycleApplet life cycle
Applet life cycle
 
Java applets
Java appletsJava applets
Java applets
 
Applet programming in java
Applet programming in javaApplet programming in java
Applet programming in java
 
Applet Architecture - Introducing Java Applets
Applet Architecture - Introducing Java AppletsApplet Architecture - Introducing Java Applets
Applet Architecture - Introducing Java Applets
 
Java applet basics
Java applet basicsJava applet basics
Java applet basics
 
java Applet Introduction
java Applet Introductionjava Applet Introduction
java Applet Introduction
 
Java applets
Java appletsJava applets
Java applets
 
Java applet - java
Java applet - javaJava applet - java
Java applet - java
 
Applet progming
Applet progmingApplet progming
Applet progming
 
6.applet programming in java
6.applet programming in java6.applet programming in java
6.applet programming in java
 
Applet execution
Applet execution Applet execution
Applet execution
 
Java applets
Java appletsJava applets
Java applets
 
Java Applet
Java AppletJava Applet
Java Applet
 
Applet in java
Applet in javaApplet in java
Applet in java
 
Java applets
Java appletsJava applets
Java applets
 
Basics of applets.53
Basics of applets.53Basics of applets.53
Basics of applets.53
 
applet using java
applet using javaapplet using java
applet using java
 
Applet skelton58
Applet skelton58Applet skelton58
Applet skelton58
 

Viewers also liked

Java Programming- Introduction to Java Applet Programs
Java Programming- Introduction to Java Applet ProgramsJava Programming- Introduction to Java Applet Programs
Java Programming- Introduction to Java Applet Programs
Trinity Dwarka
 
Java: Java Applets
Java: Java AppletsJava: Java Applets
Java: Java Applets
Tareq Hasan
 
Applet Vs Servlet
Applet Vs ServletApplet Vs Servlet
Applet Vs Servlet
Bharat Sahu
 
Peer-to-Peer Review
Peer-to-Peer ReviewPeer-to-Peer Review
Peer-to-Peer Review
Kathleen Fitzpatrick
 
Java applet programming using jdbc2
Java applet programming using jdbc2Java applet programming using jdbc2
Java applet programming using jdbc2
Yasser Khatib
 
validation
validationvalidation
validation
teach4uin
 
Applets in java
Applets in javaApplets in java
Applets in java
Wani Zahoor
 
Controls
ControlsControls
Controls
teach4uin
 
Applet and graphics programming
Applet and graphics programmingApplet and graphics programming
Applet and graphics programming
mcanotes
 
Open and Close Door ppt
 Open and Close Door ppt Open and Close Door ppt
Open and Close Door ppt
Devyani Vaidya
 
L13 string handling(string class)
L13 string handling(string class)L13 string handling(string class)
L13 string handling(string class)
teach4uin
 
Java Inheritance
Java InheritanceJava Inheritance
Java Inheritance
Rosie Jane Enomar
 
String and string buffer
String and string bufferString and string buffer
String and string buffer
kamal kotecha
 
Java inheritance
Java inheritanceJava inheritance
Java inheritance
Arati Gadgil
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
Tech_MX
 

Viewers also liked (15)

Java Programming- Introduction to Java Applet Programs
Java Programming- Introduction to Java Applet ProgramsJava Programming- Introduction to Java Applet Programs
Java Programming- Introduction to Java Applet Programs
 
Java: Java Applets
Java: Java AppletsJava: Java Applets
Java: Java Applets
 
Applet Vs Servlet
Applet Vs ServletApplet Vs Servlet
Applet Vs Servlet
 
Peer-to-Peer Review
Peer-to-Peer ReviewPeer-to-Peer Review
Peer-to-Peer Review
 
Java applet programming using jdbc2
Java applet programming using jdbc2Java applet programming using jdbc2
Java applet programming using jdbc2
 
validation
validationvalidation
validation
 
Applets in java
Applets in javaApplets in java
Applets in java
 
Controls
ControlsControls
Controls
 
Applet and graphics programming
Applet and graphics programmingApplet and graphics programming
Applet and graphics programming
 
Open and Close Door ppt
 Open and Close Door ppt Open and Close Door ppt
Open and Close Door ppt
 
L13 string handling(string class)
L13 string handling(string class)L13 string handling(string class)
L13 string handling(string class)
 
Java Inheritance
Java InheritanceJava Inheritance
Java Inheritance
 
String and string buffer
String and string bufferString and string buffer
String and string buffer
 
Java inheritance
Java inheritanceJava inheritance
Java inheritance
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
 

Similar to L18 applets

Applets
AppletsApplets
Applets
Nuha Noor
 
Java applet
Java appletJava applet
Java applet
GaneshKumarKanthiah
 
GUI.pdf
GUI.pdfGUI.pdf
GUI.pdf
Poornima E.G.
 
Applet in java new
Applet in java newApplet in java new
Applet in java new
Kavitha713564
 
Applets
AppletsApplets
Java chapter 7
Java chapter 7Java chapter 7
Java chapter 7
Abdii Rashid
 
Applet in java
Applet in javaApplet in java
Applet in java
Rakesh Mittal
 
Basic of Applet
Basic of AppletBasic of Applet
Basic of Applet
suraj pandey
 
Applets
AppletsApplets
Applets
Inayat Sharma
 
Applets
AppletsApplets
Applet ppt for higher understanding education
Applet ppt for higher understanding educationApplet ppt for higher understanding education
Applet ppt for higher understanding education
BhanuPriya93439
 
Applets
AppletsApplets
Applets
Rishav Upreti
 
Applets
AppletsApplets
Slide8appletv2 091028110313-phpapp01
Slide8appletv2 091028110313-phpapp01Slide8appletv2 091028110313-phpapp01
Slide8appletv2 091028110313-phpapp01
Abhishek Khune
 
Unit 7 Java
Unit 7 JavaUnit 7 Java
Unit 7 Java
arnold 7490
 
Applets 101-fa06
Applets 101-fa06Applets 101-fa06
Applets 101-fa06
nrayan
 
Applets
AppletsApplets
Applets
poojapainter
 
Applets
AppletsApplets
Applets
SanthiNivas
 
Applet
AppletApplet
Applet
Amir Shokri
 
Applet and graphics programming
Applet and graphics programmingApplet and graphics programming
Applet and graphics programming
srijavel
 

Similar to L18 applets (20)

Applets
AppletsApplets
Applets
 
Java applet
Java appletJava applet
Java applet
 
GUI.pdf
GUI.pdfGUI.pdf
GUI.pdf
 
Applet in java new
Applet in java newApplet in java new
Applet in java new
 
Applets
AppletsApplets
Applets
 
Java chapter 7
Java chapter 7Java chapter 7
Java chapter 7
 
Applet in java
Applet in javaApplet in java
Applet in java
 
Basic of Applet
Basic of AppletBasic of Applet
Basic of Applet
 
Applets
AppletsApplets
Applets
 
Applets
AppletsApplets
Applets
 
Applet ppt for higher understanding education
Applet ppt for higher understanding educationApplet ppt for higher understanding education
Applet ppt for higher understanding education
 
Applets
AppletsApplets
Applets
 
Applets
AppletsApplets
Applets
 
Slide8appletv2 091028110313-phpapp01
Slide8appletv2 091028110313-phpapp01Slide8appletv2 091028110313-phpapp01
Slide8appletv2 091028110313-phpapp01
 
Unit 7 Java
Unit 7 JavaUnit 7 Java
Unit 7 Java
 
Applets 101-fa06
Applets 101-fa06Applets 101-fa06
Applets 101-fa06
 
Applets
AppletsApplets
Applets
 
Applets
AppletsApplets
Applets
 
Applet
AppletApplet
Applet
 
Applet and graphics programming
Applet and graphics programmingApplet and graphics programming
Applet and graphics programming
 

More from teach4uin

validation
validationvalidation
validation
teach4uin
 
Master pages
Master pagesMaster pages
Master pages
teach4uin
 
.Net framework
.Net framework.Net framework
.Net framework
teach4uin
 
Scripting languages
Scripting languagesScripting languages
Scripting languages
teach4uin
 
Css1
Css1Css1
Css1
teach4uin
 
Code model
Code modelCode model
Code model
teach4uin
 
Asp db
Asp dbAsp db
Asp db
teach4uin
 
State management
State managementState management
State management
teach4uin
 
security configuration
security configurationsecurity configuration
security configuration
teach4uin
 
static dynamic html tags
 static dynamic html tags static dynamic html tags
static dynamic html tags
teach4uin
 
static dynamic html tags
static dynamic html tagsstatic dynamic html tags
static dynamic html tags
teach4uin
 
New microsoft office power point presentation
New microsoft office power point presentationNew microsoft office power point presentation
New microsoft office power point presentation
teach4uin
 
.Net overview
.Net overview.Net overview
.Net overview
teach4uin
 
Stdlib functions lesson
Stdlib functions lessonStdlib functions lesson
Stdlib functions lesson
teach4uin
 
enums
enumsenums
enums
teach4uin
 
memory
memorymemory
memory
teach4uin
 
array
arrayarray
array
teach4uin
 
storage clas
storage classtorage clas
storage clas
teach4uin
 
Cprogrammingprogramcontrols
CprogrammingprogramcontrolsCprogrammingprogramcontrols
Cprogrammingprogramcontrols
teach4uin
 
Cprogrammingoperator
CprogrammingoperatorCprogrammingoperator
Cprogrammingoperator
teach4uin
 

More from teach4uin (20)

validation
validationvalidation
validation
 
Master pages
Master pagesMaster pages
Master pages
 
.Net framework
.Net framework.Net framework
.Net framework
 
Scripting languages
Scripting languagesScripting languages
Scripting languages
 
Css1
Css1Css1
Css1
 
Code model
Code modelCode model
Code model
 
Asp db
Asp dbAsp db
Asp db
 
State management
State managementState management
State management
 
security configuration
security configurationsecurity configuration
security configuration
 
static dynamic html tags
 static dynamic html tags static dynamic html tags
static dynamic html tags
 
static dynamic html tags
static dynamic html tagsstatic dynamic html tags
static dynamic html tags
 
New microsoft office power point presentation
New microsoft office power point presentationNew microsoft office power point presentation
New microsoft office power point presentation
 
.Net overview
.Net overview.Net overview
.Net overview
 
Stdlib functions lesson
Stdlib functions lessonStdlib functions lesson
Stdlib functions lesson
 
enums
enumsenums
enums
 
memory
memorymemory
memory
 
array
arrayarray
array
 
storage clas
storage classtorage clas
storage clas
 
Cprogrammingprogramcontrols
CprogrammingprogramcontrolsCprogrammingprogramcontrols
Cprogrammingprogramcontrols
 
Cprogrammingoperator
CprogrammingoperatorCprogrammingoperator
Cprogrammingoperator
 

Recently uploaded

The Role of IoT in Australian Mobile App Development - PDF Guide
The Role of IoT in Australian Mobile App Development - PDF GuideThe Role of IoT in Australian Mobile App Development - PDF Guide
The Role of IoT in Australian Mobile App Development - PDF Guide
Shiv Technolabs
 
Uncharted Together- Navigating AI's New Frontiers in Libraries
Uncharted Together- Navigating AI's New Frontiers in LibrariesUncharted Together- Navigating AI's New Frontiers in Libraries
Uncharted Together- Navigating AI's New Frontiers in Libraries
Brian Pichman
 
(CISOPlatform Summit & SACON 2024) Regulation & Response In Banks.pdf
(CISOPlatform Summit & SACON 2024) Regulation & Response In Banks.pdf(CISOPlatform Summit & SACON 2024) Regulation & Response In Banks.pdf
(CISOPlatform Summit & SACON 2024) Regulation & Response In Banks.pdf
Priyanka Aash
 
leewayhertz.com-Generative AI tech stack Frameworks infrastructure models and...
leewayhertz.com-Generative AI tech stack Frameworks infrastructure models and...leewayhertz.com-Generative AI tech stack Frameworks infrastructure models and...
leewayhertz.com-Generative AI tech stack Frameworks infrastructure models and...
alexjohnson7307
 
Integrating Kafka with MuleSoft 4 and usecase
Integrating Kafka with MuleSoft 4 and usecaseIntegrating Kafka with MuleSoft 4 and usecase
Integrating Kafka with MuleSoft 4 and usecase
shyamraj55
 
(CISOPlatform Summit & SACON 2024) Workshop _ Most Dangerous Attack Technique...
(CISOPlatform Summit & SACON 2024) Workshop _ Most Dangerous Attack Technique...(CISOPlatform Summit & SACON 2024) Workshop _ Most Dangerous Attack Technique...
(CISOPlatform Summit & SACON 2024) Workshop _ Most Dangerous Attack Technique...
Priyanka Aash
 
Dublin_mulesoft_meetup_Mulesoft_Salesforce_Integration (1).pptx
Dublin_mulesoft_meetup_Mulesoft_Salesforce_Integration (1).pptxDublin_mulesoft_meetup_Mulesoft_Salesforce_Integration (1).pptx
Dublin_mulesoft_meetup_Mulesoft_Salesforce_Integration (1).pptx
Kunal Gupta
 
Litestack talk at Brighton 2024 (Unleashing the power of SQLite for Ruby apps)
Litestack talk at Brighton 2024 (Unleashing the power of SQLite for Ruby apps)Litestack talk at Brighton 2024 (Unleashing the power of SQLite for Ruby apps)
Litestack talk at Brighton 2024 (Unleashing the power of SQLite for Ruby apps)
Muhammad Ali
 
leewayhertz.com-AI agents for healthcare Applications benefits and implementa...
leewayhertz.com-AI agents for healthcare Applications benefits and implementa...leewayhertz.com-AI agents for healthcare Applications benefits and implementa...
leewayhertz.com-AI agents for healthcare Applications benefits and implementa...
alexjohnson7307
 
Introduction-to-the-IAM-Platform-Implementation-Plan.pptx
Introduction-to-the-IAM-Platform-Implementation-Plan.pptxIntroduction-to-the-IAM-Platform-Implementation-Plan.pptx
Introduction-to-the-IAM-Platform-Implementation-Plan.pptx
313mohammedarshad
 
EuroPython 2024 - Streamlining Testing in a Large Python Codebase
EuroPython 2024 - Streamlining Testing in a Large Python CodebaseEuroPython 2024 - Streamlining Testing in a Large Python Codebase
EuroPython 2024 - Streamlining Testing in a Large Python Codebase
Jimmy Lai
 
Evolution of iPaaS - simplify IT workloads to provide a unified view of data...
Evolution of iPaaS - simplify IT workloads to provide a unified view of  data...Evolution of iPaaS - simplify IT workloads to provide a unified view of  data...
Evolution of iPaaS - simplify IT workloads to provide a unified view of data...
Torry Harris
 
Vulnerability Management: A Comprehensive Overview
Vulnerability Management: A Comprehensive OverviewVulnerability Management: A Comprehensive Overview
Vulnerability Management: A Comprehensive Overview
Steven Carlson
 
Use Cases & Benefits of RPA in Manufacturing in 2024.pptx
Use Cases & Benefits of RPA in Manufacturing in 2024.pptxUse Cases & Benefits of RPA in Manufacturing in 2024.pptx
Use Cases & Benefits of RPA in Manufacturing in 2024.pptx
SynapseIndia
 
Russian Girls Call Navi Mumbai 🎈🔥9920725232 🔥💋🎈 Provide Best And Top Girl Ser...
Russian Girls Call Navi Mumbai 🎈🔥9920725232 🔥💋🎈 Provide Best And Top Girl Ser...Russian Girls Call Navi Mumbai 🎈🔥9920725232 🔥💋🎈 Provide Best And Top Girl Ser...
Russian Girls Call Navi Mumbai 🎈🔥9920725232 🔥💋🎈 Provide Best And Top Girl Ser...
bellared2
 
Tailored CRM Software Development for Enhanced Customer Insights
Tailored CRM Software Development for Enhanced Customer InsightsTailored CRM Software Development for Enhanced Customer Insights
Tailored CRM Software Development for Enhanced Customer Insights
SynapseIndia
 
(CISOPlatform Summit & SACON 2024) Gen AI & Deepfake In Overall Security.pdf
(CISOPlatform Summit & SACON 2024) Gen AI & Deepfake In Overall Security.pdf(CISOPlatform Summit & SACON 2024) Gen AI & Deepfake In Overall Security.pdf
(CISOPlatform Summit & SACON 2024) Gen AI & Deepfake In Overall Security.pdf
Priyanka Aash
 
(CISOPlatform Summit & SACON 2024) Digital Personal Data Protection Act.pdf
(CISOPlatform Summit & SACON 2024) Digital Personal Data Protection Act.pdf(CISOPlatform Summit & SACON 2024) Digital Personal Data Protection Act.pdf
(CISOPlatform Summit & SACON 2024) Digital Personal Data Protection Act.pdf
Priyanka Aash
 
Premium Girls Call Mumbai 9920725232 Unlimited Short Providing Girls Service ...
Premium Girls Call Mumbai 9920725232 Unlimited Short Providing Girls Service ...Premium Girls Call Mumbai 9920725232 Unlimited Short Providing Girls Service ...
Premium Girls Call Mumbai 9920725232 Unlimited Short Providing Girls Service ...
shanihomely
 
High Profile Girls call Service Pune 000XX00000 Provide Best And Top Girl Ser...
High Profile Girls call Service Pune 000XX00000 Provide Best And Top Girl Ser...High Profile Girls call Service Pune 000XX00000 Provide Best And Top Girl Ser...
High Profile Girls call Service Pune 000XX00000 Provide Best And Top Girl Ser...
bhumivarma35300
 

Recently uploaded (20)

The Role of IoT in Australian Mobile App Development - PDF Guide
The Role of IoT in Australian Mobile App Development - PDF GuideThe Role of IoT in Australian Mobile App Development - PDF Guide
The Role of IoT in Australian Mobile App Development - PDF Guide
 
Uncharted Together- Navigating AI's New Frontiers in Libraries
Uncharted Together- Navigating AI's New Frontiers in LibrariesUncharted Together- Navigating AI's New Frontiers in Libraries
Uncharted Together- Navigating AI's New Frontiers in Libraries
 
(CISOPlatform Summit & SACON 2024) Regulation & Response In Banks.pdf
(CISOPlatform Summit & SACON 2024) Regulation & Response In Banks.pdf(CISOPlatform Summit & SACON 2024) Regulation & Response In Banks.pdf
(CISOPlatform Summit & SACON 2024) Regulation & Response In Banks.pdf
 
leewayhertz.com-Generative AI tech stack Frameworks infrastructure models and...
leewayhertz.com-Generative AI tech stack Frameworks infrastructure models and...leewayhertz.com-Generative AI tech stack Frameworks infrastructure models and...
leewayhertz.com-Generative AI tech stack Frameworks infrastructure models and...
 
Integrating Kafka with MuleSoft 4 and usecase
Integrating Kafka with MuleSoft 4 and usecaseIntegrating Kafka with MuleSoft 4 and usecase
Integrating Kafka with MuleSoft 4 and usecase
 
(CISOPlatform Summit & SACON 2024) Workshop _ Most Dangerous Attack Technique...
(CISOPlatform Summit & SACON 2024) Workshop _ Most Dangerous Attack Technique...(CISOPlatform Summit & SACON 2024) Workshop _ Most Dangerous Attack Technique...
(CISOPlatform Summit & SACON 2024) Workshop _ Most Dangerous Attack Technique...
 
Dublin_mulesoft_meetup_Mulesoft_Salesforce_Integration (1).pptx
Dublin_mulesoft_meetup_Mulesoft_Salesforce_Integration (1).pptxDublin_mulesoft_meetup_Mulesoft_Salesforce_Integration (1).pptx
Dublin_mulesoft_meetup_Mulesoft_Salesforce_Integration (1).pptx
 
Litestack talk at Brighton 2024 (Unleashing the power of SQLite for Ruby apps)
Litestack talk at Brighton 2024 (Unleashing the power of SQLite for Ruby apps)Litestack talk at Brighton 2024 (Unleashing the power of SQLite for Ruby apps)
Litestack talk at Brighton 2024 (Unleashing the power of SQLite for Ruby apps)
 
leewayhertz.com-AI agents for healthcare Applications benefits and implementa...
leewayhertz.com-AI agents for healthcare Applications benefits and implementa...leewayhertz.com-AI agents for healthcare Applications benefits and implementa...
leewayhertz.com-AI agents for healthcare Applications benefits and implementa...
 
Introduction-to-the-IAM-Platform-Implementation-Plan.pptx
Introduction-to-the-IAM-Platform-Implementation-Plan.pptxIntroduction-to-the-IAM-Platform-Implementation-Plan.pptx
Introduction-to-the-IAM-Platform-Implementation-Plan.pptx
 
EuroPython 2024 - Streamlining Testing in a Large Python Codebase
EuroPython 2024 - Streamlining Testing in a Large Python CodebaseEuroPython 2024 - Streamlining Testing in a Large Python Codebase
EuroPython 2024 - Streamlining Testing in a Large Python Codebase
 
Evolution of iPaaS - simplify IT workloads to provide a unified view of data...
Evolution of iPaaS - simplify IT workloads to provide a unified view of  data...Evolution of iPaaS - simplify IT workloads to provide a unified view of  data...
Evolution of iPaaS - simplify IT workloads to provide a unified view of data...
 
Vulnerability Management: A Comprehensive Overview
Vulnerability Management: A Comprehensive OverviewVulnerability Management: A Comprehensive Overview
Vulnerability Management: A Comprehensive Overview
 
Use Cases & Benefits of RPA in Manufacturing in 2024.pptx
Use Cases & Benefits of RPA in Manufacturing in 2024.pptxUse Cases & Benefits of RPA in Manufacturing in 2024.pptx
Use Cases & Benefits of RPA in Manufacturing in 2024.pptx
 
Russian Girls Call Navi Mumbai 🎈🔥9920725232 🔥💋🎈 Provide Best And Top Girl Ser...
Russian Girls Call Navi Mumbai 🎈🔥9920725232 🔥💋🎈 Provide Best And Top Girl Ser...Russian Girls Call Navi Mumbai 🎈🔥9920725232 🔥💋🎈 Provide Best And Top Girl Ser...
Russian Girls Call Navi Mumbai 🎈🔥9920725232 🔥💋🎈 Provide Best And Top Girl Ser...
 
Tailored CRM Software Development for Enhanced Customer Insights
Tailored CRM Software Development for Enhanced Customer InsightsTailored CRM Software Development for Enhanced Customer Insights
Tailored CRM Software Development for Enhanced Customer Insights
 
(CISOPlatform Summit & SACON 2024) Gen AI & Deepfake In Overall Security.pdf
(CISOPlatform Summit & SACON 2024) Gen AI & Deepfake In Overall Security.pdf(CISOPlatform Summit & SACON 2024) Gen AI & Deepfake In Overall Security.pdf
(CISOPlatform Summit & SACON 2024) Gen AI & Deepfake In Overall Security.pdf
 
(CISOPlatform Summit & SACON 2024) Digital Personal Data Protection Act.pdf
(CISOPlatform Summit & SACON 2024) Digital Personal Data Protection Act.pdf(CISOPlatform Summit & SACON 2024) Digital Personal Data Protection Act.pdf
(CISOPlatform Summit & SACON 2024) Digital Personal Data Protection Act.pdf
 
Premium Girls Call Mumbai 9920725232 Unlimited Short Providing Girls Service ...
Premium Girls Call Mumbai 9920725232 Unlimited Short Providing Girls Service ...Premium Girls Call Mumbai 9920725232 Unlimited Short Providing Girls Service ...
Premium Girls Call Mumbai 9920725232 Unlimited Short Providing Girls Service ...
 
High Profile Girls call Service Pune 000XX00000 Provide Best And Top Girl Ser...
High Profile Girls call Service Pune 000XX00000 Provide Best And Top Girl Ser...High Profile Girls call Service Pune 000XX00000 Provide Best And Top Girl Ser...
High Profile Girls call Service Pune 000XX00000 Provide Best And Top Girl Ser...
 

L18 applets

  • 2. Introduction • A Java applet is a special kind of Java program that a java- enabled browser can download from the internet and run. • An applet is typically embedded inside a web page and runs in the context of a browser. • An applet must be a subclass of the java.applet.Applet class. • The Applet class provides the standard interface between the applet and the browser environment.
  • 3. • Applets are not stand-alone programs. • Instead, they run within either a web browser or an applet viewer. • Execution of an applet does not begin at main( ). • Output to applet’s window is not performed by System.out.println( ).
  • 4. Types of Applets • There are two types of applets. • The first are based directly on the Applet class and use the AWT to provide the graphic user interface. • These applets has been available since Java was first created. • The second type of applets are based on the Swing class JApplet. • Swing applets use the Swing classes to provide the GUI.
  • 5. • Swing offers a richer and often easier-to-use user interface than does the AWT. • Swing-based applets are now the most popular. However, traditional AWT-based applets are still used, especially when only a very simple user interface is required. • Thus, both AWT and Swing-based applets are valid. • Because JApplet inherits Applet, all the features of Applet are also available in JApplet
  • 6. Applet Class • Applet provides all necessary support for applet execution, such as starting and stopping. • It also provides methods that load and display images, and methods that load and play audio clips. • Applet extends the AWT class Panel. In turn, Panel extends Container, which extends Component.
  • 8. Applet Methods called by the system • public void init() To initialize the Applet When the applet is first loaded. • public void start() Starts applet when the applet is displayed. Automatically called after init( ) when an applet first begins. • public void stop() When the browser leaves the page containing the applet. • public void destroy() Called by the browser just before an applet is terminated. • public void paint(Graphics g)
  • 9. Applet Initialization and Termination • When an applet begins, the following methods are called, in this sequence: 1.init( ) 2.start( ) 3.paint( ) • When an applet is terminated, the following sequence of method calls takes place: 1.stop( ) 2.destroy( )
  • 10. init( ) • The init( ) method is the first method to be called. • This is where we should initialize variables. • This method is called only once during the run time of your applet.
  • 11. start( ) • The start( ) method is called after init( ). • It is also called to restart an applet after it has been stopped. • init( )is called once—the first time an applet is loaded whereas start( ) is called each time an applet’s HTML document is displayed on screen. • So, if a user leaves a web page and comes back, the applet resumes execution at start( ).
  • 12. paint( ) • The paint( ) method is called each time the applet’s output must be redrawn. • This situation can occur for several reasons. For example, the window in which the applet is running may be overwritten by another window and then uncovered. Or the applet window may be minimized and then restored. • paint( ) is also called when the applet begins execution. • The paint( ) method has one parameter of type Graphics, which describes the graphics environment in which the applet is running.
  • 13. stop( ) • The stop( ) method is called when a web browser leaves the HTML document containing the applet(e.g. when it goes to another page). • When stop( )is called, the applet may be running. We can restart them when start( )is called if the user returns to the page.
  • 14. destroy( ) • The destroy( ) method is called when the environment determines that the applet needs to be removed completely from memory. • It frees up any resources the applet may be using. • The stop( ) method is always called before destroy( ).
  • 17. • The Graphics class provides the methods for drawing strings, lines, rectangles, ovals, arcs, polygons, and polylines. • void setColor(Color c) • void setFont(Font f) • void drawString(String s, int x, int y) • void drawLine(int x1, int y1, int x2, int y2) • void drawRect(int x, int y, int w, int h) • void fillRect(int x, int y, int w, int h) • void drawRoundRect(int x, int y, int w, int h, int aw, int ah) • void fillRoundRect(int x, int y, int w, int h, int aw, int ah) Graphics Methods
  • 18. • void drawOval(int x, int y, int w, int h) • void fillOval(int x, int y, int w, int h) • void drawArc(int x, int y, int w, int h, int start_angle, int arc_angle) • void fillArc(int x, int y, int w, int h, int start_angle, int arc_angle) • void drawPolygon (int [] x, int [] y, int n_point) • void fillPolygon (int [] x, int [] y, int n_point) • void drawPolyline (int [] x, int [] y, int n_point) Graphics Methods
  • 19. Color class • We can set colors for GUI components by using the java.awt.Color class. • We can use one of the 13 standard colors (BLACK, BLUE, CYAN, DARK_GRAY, GRAY, GREEN, LIGHT_GRAY, MAGENTA, ORANGE, PINK, RED, WHITE, and YELLOW) defined as constants in java.awt.Color. • Colors are made of red, green, and blue components, each represented by an int value that describes its intensity, ranging from 0(lightest shade) to 255(darkest shade). This is known as the RGB model.
  • 20. • We can create a color using the following constructor: public Color(int r, int g, int b); • Color color = new Color(128,100,100); • The arguments r, g, b are between 0 and 255. If a value beyond this range is passed to the argument, an IllegalArgumentException will occur. Example: JButton jb1 = new JButton("OK"); jb1.setBackground(color); jb1.setForeground (new Color(100,1,1));
  • 21. Font class • We can create a font using the java.awt.Font class and set fonts for the components using the setFont method in the Component class. • The constructor for Font is: public Font (String name, int style, int size); • You can choose a font name from SansSerif, Serif, Monospaced, Dialog, or DialogInput. • Choose a style from Font.PLAIN(0), Font.BOLD(1), Font.ITALIC(2), and Font.BOLD+Font.ITALIC(3), and specify a font size of any positive integer.
  • 22. Font class • Example: Font font1 = new Font("SansSerif", Font.BOLD, 16); Font font2 = new Font("Serif", Font.BOLD + Font.ITALIC, 12); JButton jbtOK = new JButton("OK"); jbtOK.setFont(font1);
  • 23. setBackground() & setForeground() • To set the background color of an applet’s window, we use setBackground( ). void setBackground(Color newColor) • To set the foreground color (the color in which text is shown, for example), we use setForeground( ). void setForeground(Color newColor) • These methods are defined by Component. • A good place to set the foreground and background colors is in the init( ) method.
  • 24. Simple Applet Display Methods drawString( ) • used to output a string to an applet. • is a member of the Graphics class. • called from within either update( ) or paint( ). void drawString (String message, int x, int y) • The drawString( ) method will not recognize new line characters. • If we want to start a line of text on another line, we must do so manually, specifying the precise X, Y location where we want the line to begin.
  • 25. repaint() • Whenever an applet needs to update the information displayed in its window, it simply calls repaint( ). • The repaint( ) method is defined by the AWT. • It causes the AWT run-time system to execute a call to applet’s update( ) method, which, in its default implementation, calls paint( ). void repaint( ) void repaint(int left, int top, int width, int height) void repaint(long maxDelay) void repaint(long maxDelay, int x, int y, int width, int height)
  • 26. Example import java.awt.*; import java.applet.*; /* <applet code="Banner" width=300 height=50> </applet> */ public class Banner extends Applet implements Runnable { String msg = " Ravi Kant Sahu "; Thread t = null; int state; boolean stopFlag; // Set colors and initialize thread. public void init() { setBackground(Color.cyan); setForeground(Color.red); }
  • 27. // Start thread public void start() { t = new Thread(this); stopFlag = false; t.start(); } public void run() { char ch; // Display banner for( ; ; ) { try { repaint(); Thread.sleep(450); ch = msg.charAt(0); msg = msg.substring(1, msg.length()); msg += ch; if(stopFlag) break; } catch(InterruptedException e) {} } }
  • 28. // Pause the banner. public void stop() { stopFlag = true; t = null; } // Display the banner. public void paint(Graphics g) { g.drawString(msg, 50, 30); } }
  • 29. Status Window in Applets • An applet can output a message to the status window of the browser or applet viewer on which it is running. • showStatus( ) method is used to display the status message. • The status window is a good place to give the user feedback about what is occurring in the applet, suggest options, or possibly report some types of errors.
  • 30. Example import java.awt.*; import java.applet.*; /* <applet code="StatusWindow" width=300 height=50> </applet> */ public class StatusWindow extends Applet { public void init() { setBackground(Color.cyan); } public void paint(Graphics g) { g.drawString("Ravi Kant Sahu", 10, 20); showStatus("This applet is running on Appletviewer."); } }

Editor's Notes

  1. aw is arc width and ah is arc height
  2. aw is arc width and ah is arc height