SlideShare a Scribd company logo
Programming in JAVA
Topic: Applets
By
Ravi Kant Sahu
Asst. Professor

Lovely Professional University, Punjab
Introduction
• A Java applet is a special kind of Java program that a javaenabled 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.

Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
• 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( ).

Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
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.
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
• 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
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
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.

Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Applet Class Hierarchy

Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
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)
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
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( )

Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
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.

Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
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( ).

Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
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.
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
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.

Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
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( ).

Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Graphics Class

Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Graphics Methods
• 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(Strig 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)
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
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 drawPolygon (int [] x, int [] y, int n_point)
• void drawPolyline (int [] x, int [] y, int n_point)
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
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.

Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
• 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));

Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
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.

Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
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);

Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
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.
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
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.
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
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)
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
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);
}
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
// 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) {}
}
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
}
// Pause the banner.
public void stop()
{
stopFlag = true;
t = null;
}
// Display the banner.
public void paint(Graphics g)
{
g.drawString(msg, 50, 30);
}
}

Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
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.

Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
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.");
}
}
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)

More Related Content

What's hot

OCA Java SE 8 Exam Chapter 1 Java Building Blocks
OCA Java SE 8 Exam Chapter 1 Java Building BlocksOCA Java SE 8 Exam Chapter 1 Java Building Blocks
OCA Java SE 8 Exam Chapter 1 Java Building BlocksÄ°brahim KĂĽrce
 
Python Programming - VI. Classes and Objects
Python Programming - VI. Classes and ObjectsPython Programming - VI. Classes and Objects
Python Programming - VI. Classes and ObjectsRanel Padon
 
The Go Programing Language 1
The Go Programing Language 1The Go Programing Language 1
The Go Programing Language 1Ä°brahim KĂĽrce
 
Java se 8 fundamentals
Java se 8 fundamentalsJava se 8 fundamentals
Java se 8 fundamentalsmegharajk
 
OCP Java (OCPJP) 8 Exam Quick Reference Card
OCP Java (OCPJP) 8 Exam Quick Reference CardOCP Java (OCPJP) 8 Exam Quick Reference Card
OCP Java (OCPJP) 8 Exam Quick Reference CardHari kiran G
 
Object Oriented Programming with Java
Object Oriented Programming with JavaObject Oriented Programming with Java
Object Oriented Programming with JavaJussi Pohjolainen
 
OCA Java SE 8 Exam Chapter 2 Operators & Statements
OCA Java SE 8 Exam Chapter 2 Operators & StatementsOCA Java SE 8 Exam Chapter 2 Operators & Statements
OCA Java SE 8 Exam Chapter 2 Operators & StatementsÄ°brahim KĂĽrce
 
Generics in java
Generics in javaGenerics in java
Generics in javasuraj pandey
 
Java Generics
Java GenericsJava Generics
Java GenericsDeeptiJava
 
OCA Java SE 8 Exam Chapter 3 Core Java APIs
OCA Java SE 8 Exam Chapter 3 Core Java APIsOCA Java SE 8 Exam Chapter 3 Core Java APIs
OCA Java SE 8 Exam Chapter 3 Core Java APIsÄ°brahim KĂĽrce
 
Java Interview Questions For Freshers
Java Interview Questions For FreshersJava Interview Questions For Freshers
Java Interview Questions For Fresherszynofustechnology
 
Ap Power Point Chpt7
Ap Power Point Chpt7Ap Power Point Chpt7
Ap Power Point Chpt7dplunkett
 
Object Oriented Programming Concepts
Object Oriented Programming ConceptsObject Oriented Programming Concepts
Object Oriented Programming ConceptsBhushan Nagaraj
 
Chapter 06 constructors and destructors
Chapter 06 constructors and destructorsChapter 06 constructors and destructors
Chapter 06 constructors and destructorsPraveen M Jigajinni
 
Core java
Core javaCore java
Core javaShivaraj R
 
Unit 1 Java
Unit 1 JavaUnit 1 Java
Unit 1 Javaarnold 7490
 

What's hot (20)

Swing api
Swing apiSwing api
Swing api
 
Multi threading
Multi threadingMulti threading
Multi threading
 
OCA Java SE 8 Exam Chapter 1 Java Building Blocks
OCA Java SE 8 Exam Chapter 1 Java Building BlocksOCA Java SE 8 Exam Chapter 1 Java Building Blocks
OCA Java SE 8 Exam Chapter 1 Java Building Blocks
 
Python Programming - VI. Classes and Objects
Python Programming - VI. Classes and ObjectsPython Programming - VI. Classes and Objects
Python Programming - VI. Classes and Objects
 
The Go Programing Language 1
The Go Programing Language 1The Go Programing Language 1
The Go Programing Language 1
 
Java se 8 fundamentals
Java se 8 fundamentalsJava se 8 fundamentals
Java se 8 fundamentals
 
OCP Java (OCPJP) 8 Exam Quick Reference Card
OCP Java (OCPJP) 8 Exam Quick Reference CardOCP Java (OCPJP) 8 Exam Quick Reference Card
OCP Java (OCPJP) 8 Exam Quick Reference Card
 
Basics of Java
Basics of JavaBasics of Java
Basics of Java
 
Object Oriented Programming with Java
Object Oriented Programming with JavaObject Oriented Programming with Java
Object Oriented Programming with Java
 
Java Basics
Java BasicsJava Basics
Java Basics
 
OCA Java SE 8 Exam Chapter 2 Operators & Statements
OCA Java SE 8 Exam Chapter 2 Operators & StatementsOCA Java SE 8 Exam Chapter 2 Operators & Statements
OCA Java SE 8 Exam Chapter 2 Operators & Statements
 
Generics in java
Generics in javaGenerics in java
Generics in java
 
Java Generics
Java GenericsJava Generics
Java Generics
 
OCA Java SE 8 Exam Chapter 3 Core Java APIs
OCA Java SE 8 Exam Chapter 3 Core Java APIsOCA Java SE 8 Exam Chapter 3 Core Java APIs
OCA Java SE 8 Exam Chapter 3 Core Java APIs
 
Java Interview Questions For Freshers
Java Interview Questions For FreshersJava Interview Questions For Freshers
Java Interview Questions For Freshers
 
Ap Power Point Chpt7
Ap Power Point Chpt7Ap Power Point Chpt7
Ap Power Point Chpt7
 
Object Oriented Programming Concepts
Object Oriented Programming ConceptsObject Oriented Programming Concepts
Object Oriented Programming Concepts
 
Chapter 06 constructors and destructors
Chapter 06 constructors and destructorsChapter 06 constructors and destructors
Chapter 06 constructors and destructors
 
Core java
Core javaCore java
Core java
 
Unit 1 Java
Unit 1 JavaUnit 1 Java
Unit 1 Java
 

Viewers also liked

tL19 awt
tL19 awttL19 awt
tL19 awtteach4uin
 
Keywords and classes
Keywords and classesKeywords and classes
Keywords and classesRavi_Kant_Sahu
 
Methods and constructors
Methods and constructorsMethods and constructors
Methods and constructorsRavi_Kant_Sahu
 
L2 datatypes and variables
L2 datatypes and variablesL2 datatypes and variables
L2 datatypes and variablesRavi_Kant_Sahu
 
String handling(string buffer class)
String handling(string buffer class)String handling(string buffer class)
String handling(string buffer class)Ravi_Kant_Sahu
 
Java swing
Java swingJava swing
Java swingprofbnk
 
Nosql availability & integrity
Nosql availability & integrityNosql availability & integrity
Nosql availability & integrityFahri Firdausillah
 
Introduction To Silverlight and Prism
Introduction To Silverlight and PrismIntroduction To Silverlight and Prism
Introduction To Silverlight and Prismtombeuckelaere
 
Forms authentication
Forms authenticationForms authentication
Forms authenticationSNJ Chaudhary
 

Viewers also liked (20)

Basic IO
Basic IOBasic IO
Basic IO
 
Event handling
Event handlingEvent handling
Event handling
 
Inheritance
InheritanceInheritance
Inheritance
 
JAVA AWT
JAVA AWTJAVA AWT
JAVA AWT
 
tL19 awt
tL19 awttL19 awt
tL19 awt
 
Keywords and classes
Keywords and classesKeywords and classes
Keywords and classes
 
Methods and constructors
Methods and constructorsMethods and constructors
Methods and constructors
 
Array
ArrayArray
Array
 
L2 datatypes and variables
L2 datatypes and variablesL2 datatypes and variables
L2 datatypes and variables
 
Java AWT
Java AWTJava AWT
Java AWT
 
String handling(string buffer class)
String handling(string buffer class)String handling(string buffer class)
String handling(string buffer class)
 
Wrapper classes
Wrapper classesWrapper classes
Wrapper classes
 
Packages
PackagesPackages
Packages
 
Java swing
Java swingJava swing
Java swing
 
PyCologne
PyColognePyCologne
PyCologne
 
Perl Development
Perl DevelopmentPerl Development
Perl Development
 
Nosql availability & integrity
Nosql availability & integrityNosql availability & integrity
Nosql availability & integrity
 
Introduction To Silverlight and Prism
Introduction To Silverlight and PrismIntroduction To Silverlight and Prism
Introduction To Silverlight and Prism
 
Forms authentication
Forms authenticationForms authentication
Forms authentication
 
2310 b 09
2310 b 092310 b 09
2310 b 09
 

Similar to Applets

L18 applets
L18 appletsL18 applets
L18 appletsteach4uin
 
concept of applet and concept of Layout Managers
concept of applet and concept of Layout Managersconcept of applet and concept of Layout Managers
concept of applet and concept of Layout ManagersJadavsejal
 
Basic of Applet
Basic of AppletBasic of Applet
Basic of Appletsuraj pandey
 
Applet in java
Applet in javaApplet in java
Applet in javaRakesh Mittal
 
Applets
AppletsApplets
AppletsNuha Noor
 
DSA 103 Object Oriented Programming :: Week 4
DSA 103 Object Oriented Programming :: Week 4DSA 103 Object Oriented Programming :: Week 4
DSA 103 Object Oriented Programming :: Week 4Ferdin Joe John Joseph PhD
 
27 applet programming
27  applet programming27  applet programming
27 applet programmingRavindra Rathore
 
Applet in java new
Applet in java newApplet in java new
Applet in java newKavitha713564
 
Applets 101-fa06
Applets 101-fa06Applets 101-fa06
Applets 101-fa06nrayan
 
Java chapter 7
Java chapter 7Java chapter 7
Java chapter 7Abdii Rashid
 
java programming - applets
java programming - appletsjava programming - applets
java programming - appletsHarshithaAllu
 
Applet &amp; graphics programming
Applet &amp; graphics programmingApplet &amp; graphics programming
Applet &amp; graphics programmingShekh Ahmed
 
Applet and graphics programming
Applet and graphics programmingApplet and graphics programming
Applet and graphics programmingmcanotes
 

Similar to Applets (20)

L18 applets
L18 appletsL18 applets
L18 applets
 
concept of applet and concept of Layout Managers
concept of applet and concept of Layout Managersconcept of applet and concept of Layout Managers
concept of applet and concept of Layout Managers
 
Java Applet
Java AppletJava Applet
Java Applet
 
Basic of Applet
Basic of AppletBasic of Applet
Basic of Applet
 
Applet in java
Applet in javaApplet in java
Applet in java
 
Applets
AppletsApplets
Applets
 
DSA 103 Object Oriented Programming :: Week 4
DSA 103 Object Oriented Programming :: Week 4DSA 103 Object Oriented Programming :: Week 4
DSA 103 Object Oriented Programming :: Week 4
 
Java applet
Java appletJava applet
Java applet
 
27 applet programming
27  applet programming27  applet programming
27 applet programming
 
Applet in java new
Applet in java newApplet in java new
Applet in java new
 
Applets 101-fa06
Applets 101-fa06Applets 101-fa06
Applets 101-fa06
 
Applets
AppletsApplets
Applets
 
Applets
AppletsApplets
Applets
 
Java chapter 7
Java chapter 7Java chapter 7
Java chapter 7
 
java programming - applets
java programming - appletsjava programming - applets
java programming - applets
 
Applet &amp; graphics programming
Applet &amp; graphics programmingApplet &amp; graphics programming
Applet &amp; graphics programming
 
Applet and graphics programming
Applet and graphics programmingApplet and graphics programming
Applet and graphics programming
 
AdvancedJava.pptx
AdvancedJava.pptxAdvancedJava.pptx
AdvancedJava.pptx
 
Applet
AppletApplet
Applet
 
JavaAdvUnit-1.pptx
JavaAdvUnit-1.pptxJavaAdvUnit-1.pptx
JavaAdvUnit-1.pptx
 

Recently uploaded

To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsPaul Groth
 
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...CzechDreamin
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Jeffrey Haguewood
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...Product School
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...UiPathCommunity
 
UiPath Test Automation using UiPath Test Suite series, part 2
UiPath Test Automation using UiPath Test Suite series, part 2UiPath Test Automation using UiPath Test Suite series, part 2
UiPath Test Automation using UiPath Test Suite series, part 2DianaGray10
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersSafe Software
 
IoT Analytics Company Presentation May 2024
IoT Analytics Company Presentation May 2024IoT Analytics Company Presentation May 2024
IoT Analytics Company Presentation May 2024IoTAnalytics
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Product School
 
Optimizing NoSQL Performance Through Observability
Optimizing NoSQL Performance Through ObservabilityOptimizing NoSQL Performance Through Observability
Optimizing NoSQL Performance Through ObservabilityScyllaDB
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...Product School
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfCheryl Hung
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Thierry Lestable
 
UiPath Test Automation using UiPath Test Suite series, part 1
UiPath Test Automation using UiPath Test Suite series, part 1UiPath Test Automation using UiPath Test Suite series, part 1
UiPath Test Automation using UiPath Test Suite series, part 1DianaGray10
 
AI revolution and Salesforce, Jiří Karpíšek
AI revolution and Salesforce, Jiří KarpíšekAI revolution and Salesforce, Jiří Karpíšek
AI revolution and Salesforce, Jiří KarpíšekCzechDreamin
 
Search and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesSearch and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesBhaskar Mitra
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonDianaGray10
 
Custom Approval Process: A New Perspective, Pavel Hrbacek & Anindya Halder
Custom Approval Process: A New Perspective, Pavel Hrbacek & Anindya HalderCustom Approval Process: A New Perspective, Pavel Hrbacek & Anindya Halder
Custom Approval Process: A New Perspective, Pavel Hrbacek & Anindya HalderCzechDreamin
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...Product School
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Product School
 

Recently uploaded (20)

To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
 
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
 
UiPath Test Automation using UiPath Test Suite series, part 2
UiPath Test Automation using UiPath Test Suite series, part 2UiPath Test Automation using UiPath Test Suite series, part 2
UiPath Test Automation using UiPath Test Suite series, part 2
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 
IoT Analytics Company Presentation May 2024
IoT Analytics Company Presentation May 2024IoT Analytics Company Presentation May 2024
IoT Analytics Company Presentation May 2024
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
 
Optimizing NoSQL Performance Through Observability
Optimizing NoSQL Performance Through ObservabilityOptimizing NoSQL Performance Through Observability
Optimizing NoSQL Performance Through Observability
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 
UiPath Test Automation using UiPath Test Suite series, part 1
UiPath Test Automation using UiPath Test Suite series, part 1UiPath Test Automation using UiPath Test Suite series, part 1
UiPath Test Automation using UiPath Test Suite series, part 1
 
AI revolution and Salesforce, Jiří Karpíšek
AI revolution and Salesforce, Jiří KarpíšekAI revolution and Salesforce, Jiří Karpíšek
AI revolution and Salesforce, Jiří Karpíšek
 
Search and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesSearch and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical Futures
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
 
Custom Approval Process: A New Perspective, Pavel Hrbacek & Anindya Halder
Custom Approval Process: A New Perspective, Pavel Hrbacek & Anindya HalderCustom Approval Process: A New Perspective, Pavel Hrbacek & Anindya Halder
Custom Approval Process: A New Perspective, Pavel Hrbacek & Anindya Halder
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
 

Applets

  • 1. Programming in JAVA Topic: Applets By Ravi Kant Sahu Asst. Professor Lovely Professional University, Punjab
  • 2. Introduction • A Java applet is a special kind of Java program that a javaenabled 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. Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 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( ). Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 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. Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 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 Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 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. Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 7. Applet Class Hierarchy Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 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) Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 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( ) Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 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. Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 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( ). Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 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. Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 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. Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 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( ). Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 15. Graphics Class Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 16. Graphics Methods • 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(Strig 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) Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 17. 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 drawPolygon (int [] x, int [] y, int n_point) • void drawPolyline (int [] x, int [] y, int n_point) Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 18. 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. Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 19. • 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)); Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 20. 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. Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 21. 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); Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 22. 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. Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 23. 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. Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 24. 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) Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 25. 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); } Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 26. // 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) {} } Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India) }
  • 27. // Pause the banner. public void stop() { stopFlag = true; t = null; } // Display the banner. public void paint(Graphics g) { g.drawString(msg, 50, 30); } } Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 28. 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. Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 29. 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."); } } Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 30. Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)