SlideShare a Scribd company logo
1 of 19
IMRAN DAUD
FOUNDATION UNIVERSITY
INSTITUTE OF MANAGEMENT AND
COMPUTER SCIENCES
Imran Daud
FUIMCS
Web Engineering
Java Applets
Applets
 An applet is a Java program that a browser can
download and run.
 An applet is 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.
 Swing provides javax.swing.JApplet.
Sample Applet Code
 Two steps to turning it in to an Applet
 1. Change "extend JFrame" to "extends JApplet" and get rid of the main, you'll have to

 import javax.swing.JApplet
 public class MyApp extends JApplet {
 ...
 } // end MyApp

 2. Embed the application into the webpage, using html

 <html>
 <head>
 <title> My Applet </title
 </head>
 <body>
 <! this is the applet tag which has attributes, there must be code, width, height>
 <applet code = "MyApp.class” width = "300” height = "300”>
 <! there can be optional parameters >
 <param name="someParamName" value="paramStringValue" >
 </applet>
 </body>
 </html>
Applet Life Cycle
 loaded -> created -> initialized -> started <=> stopped -> destroyed
 The applet maybe stopped because the user has changed focused
 JApplet has methods initialized, started, stopped and destroyed phases.
They have default behavior that you can over write.
 init() - this where you can load the parameter, someParamName, with their
String values using getParamter("someParamName"). Note that order is
not important.
 start() - here you can start things after stopping
 stop() - allows you save information before stopping and to use in start()
 destroy() - allows you clean up. Note stop will be called first.
Applets have restrictions:
 Cannot read or write files on the client machine
 Cannot run programs on the client machine
 Cannot make any computer connections
But the Applet can read data files on the Sever
Steps to create Applet Projects in
Netbeans
 Choose File > New Project (Ctrl-Shift-N). Under
Categories, select Java.
 Choose one of the following:
 If you are creating a new applet source file, select Java Class
Library under Projects. Click Next.
 If you want to import an applet source file, select Java Project
with Existing Sources. Click Next. Specify the file's location in
the Source Packages Folder text box.
 Under Project Name, type HelloApplet. Change the
Project Location to any folder on your computer.
 Click Finish.
Create applet source file
 Right-click the HelloApplet project and choose Properties
to open the Properties window.
 Select the desired Source / Binary Format for the project
from source tab.
 Right-click the HelloApplet project node in the Projects
window and select New > Other (Ctrl-N).
 Under Categories, select Java. Under File Types, select
Applet.
 (for visual design applet select Swing GUI Forms > JApplet
Form.)
 Give name to applet and click finish.
Demo
 Init()
 Start()
 Stop()
 Destroy()
Setting ground for applet
 Set all static parameters in init() function. Like
 Setsize(int width, int height)
 Setbackgroundcolor()
Applet Example
Draw Lines
Drawing Shapes
 Rectangle
 Oval
 Etc (consult documentation)
Adding Mouse
 MouseListener
 MouseMotionListener
 (Consult API Documentation for function details)
Keyboard Input
 KeyListener
 actionListener
 (Consult API Documentatio)
 Panel
 JTextField
 JTextArea
 JCombobox
 etc
Java Layouts
 FlowLayout
 BorderLayout
 GridLayout
 BoxLayout
 CardLayout
 GridBagLayout
 GroupLayout
 SpringLayout
Threads
 Thread --- Class
 Runnable ---- Interface
Class --- Thread
 Public Class A extends Thread{
 Public void run(){
 }
 }
 A aa= new A();
 aa.start();
Runnable
 Public class A implements Runnable{
 Public void run(){
 }
 }
 A aa = new A();
 Thread t1 = new Thread(aa);
 t1.start();
Reference
 http://www.csl.mtu.edu/cs2321/
 Netbeans.org

More Related Content

What's hot

Java applet basics
Java applet basicsJava applet basics
Java applet basics
Sunil Pandey
 
Java applets
Java appletsJava applets
Java applets
lopjuan
 
6.applet programming in java
6.applet programming in java6.applet programming in java
6.applet programming in java
Deepak Sharma
 
Appl clas nd architect.56
Appl clas nd architect.56Appl clas nd architect.56
Appl clas nd architect.56
myrajendra
 

What's hot (20)

Java applet basics
Java applet basicsJava applet basics
Java applet basics
 
Applet progming
Applet progmingApplet progming
Applet progming
 
Applet in java
Applet in javaApplet in java
Applet in java
 
Java Applet
Java AppletJava Applet
Java Applet
 
Java applets
Java appletsJava applets
Java applets
 
Java applets
Java appletsJava applets
Java applets
 
6.applet programming in java
6.applet programming in java6.applet programming in java
6.applet programming in java
 
ITFT- Applet in java
ITFT- Applet in javaITFT- Applet in java
ITFT- Applet in java
 
first-applet
first-appletfirst-applet
first-applet
 
Java: Java Applets
Java: Java AppletsJava: Java Applets
Java: Java Applets
 
Applet programming in java
Applet programming in javaApplet programming in java
Applet programming in java
 
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 applet
Java appletJava applet
Java applet
 
Graphics programming in Java
Graphics programming in JavaGraphics programming in Java
Graphics programming in Java
 
Applet programming
Applet programming Applet programming
Applet programming
 
Java Applets
Java AppletsJava Applets
Java Applets
 
Java applets
Java appletsJava applets
Java applets
 
Applet (1)
Applet (1)Applet (1)
Applet (1)
 
Java Applets
Java AppletsJava Applets
Java Applets
 
Appl clas nd architect.56
Appl clas nd architect.56Appl clas nd architect.56
Appl clas nd architect.56
 

Viewers also liked (11)

1. intro
1. intro1. intro
1. intro
 
2. http, html
2. http, html2. http, html
2. http, html
 
6. hibernate
6. hibernate6. hibernate
6. hibernate
 
4. jsp
4. jsp4. jsp
4. jsp
 
La autoestima iefap 2013
La autoestima iefap 2013La autoestima iefap 2013
La autoestima iefap 2013
 
Sistema opertaivo
Sistema opertaivoSistema opertaivo
Sistema opertaivo
 
Introducing the WSO2 Governance Registry 4 1.5
Introducing the WSO2 Governance Registry 4 1.5 Introducing the WSO2 Governance Registry 4 1.5
Introducing the WSO2 Governance Registry 4 1.5
 
Separating klout from clout
Separating klout from cloutSeparating klout from clout
Separating klout from clout
 
5. servlets
5. servlets5. servlets
5. servlets
 
Unidad 13 union europea
Unidad 13 union europeaUnidad 13 union europea
Unidad 13 union europea
 
Eulen Seguridad-Ciberseguridad Industrial - Centro de Control de Seguridad In...
Eulen Seguridad-Ciberseguridad Industrial - Centro de Control de Seguridad In...Eulen Seguridad-Ciberseguridad Industrial - Centro de Control de Seguridad In...
Eulen Seguridad-Ciberseguridad Industrial - Centro de Control de Seguridad In...
 

Similar to 3. applets

Slide8appletv2 091028110313-phpapp01
Slide8appletv2 091028110313-phpapp01Slide8appletv2 091028110313-phpapp01
Slide8appletv2 091028110313-phpapp01
Abhishek Khune
 

Similar to 3. applets (20)

Unit 7 Java
Unit 7 JavaUnit 7 Java
Unit 7 Java
 
Applet
AppletApplet
Applet
 
Java files and io streams
Java files and io streamsJava files and io streams
Java files and io streams
 
Class notes(week 10) on applet programming
Class notes(week 10) on applet programmingClass notes(week 10) on applet programming
Class notes(week 10) on applet programming
 
oops with java modules iii & iv.pptx
oops with java modules iii & iv.pptxoops with java modules iii & iv.pptx
oops with java modules iii & iv.pptx
 
Smart material - Unit 3 (2).pdf
Smart material - Unit 3 (2).pdfSmart material - Unit 3 (2).pdf
Smart material - Unit 3 (2).pdf
 
Smart material - Unit 3 (1).pdf
Smart material - Unit 3 (1).pdfSmart material - Unit 3 (1).pdf
Smart material - Unit 3 (1).pdf
 
Applet in java new
Applet in java newApplet in java new
Applet in java new
 
Java
JavaJava
Java
 
Slide8appletv2 091028110313-phpapp01
Slide8appletv2 091028110313-phpapp01Slide8appletv2 091028110313-phpapp01
Slide8appletv2 091028110313-phpapp01
 
applet.pptx
applet.pptxapplet.pptx
applet.pptx
 
Java applet
Java appletJava applet
Java applet
 
Basic of Applet
Basic of AppletBasic of Applet
Basic of Applet
 
Applet Architecture - Introducing Java Applets
Applet Architecture - Introducing Java AppletsApplet Architecture - Introducing Java Applets
Applet Architecture - Introducing Java Applets
 
Class notes(week 10) on applet programming
Class notes(week 10) on applet programmingClass notes(week 10) on applet programming
Class notes(week 10) on applet programming
 
java applets
java appletsjava applets
java applets
 
Java applet
Java appletJava applet
Java applet
 
Applet
AppletApplet
Applet
 
Applets
AppletsApplets
Applets
 
Java applet programming concepts
Java  applet programming conceptsJava  applet programming concepts
Java applet programming concepts
 

More from AnusAhmad

More from AnusAhmad (16)

[Www.pkbulk.blogspot.com]file and indexing
[Www.pkbulk.blogspot.com]file and indexing[Www.pkbulk.blogspot.com]file and indexing
[Www.pkbulk.blogspot.com]file and indexing
 
[Www.pkbulk.blogspot.com]dbms12
[Www.pkbulk.blogspot.com]dbms12[Www.pkbulk.blogspot.com]dbms12
[Www.pkbulk.blogspot.com]dbms12
 
[Www.pkbulk.blogspot.com]dbms11
[Www.pkbulk.blogspot.com]dbms11[Www.pkbulk.blogspot.com]dbms11
[Www.pkbulk.blogspot.com]dbms11
 
[Www.pkbulk.blogspot.com]dbms10
[Www.pkbulk.blogspot.com]dbms10[Www.pkbulk.blogspot.com]dbms10
[Www.pkbulk.blogspot.com]dbms10
 
[Www.pkbulk.blogspot.com]dbms09
[Www.pkbulk.blogspot.com]dbms09[Www.pkbulk.blogspot.com]dbms09
[Www.pkbulk.blogspot.com]dbms09
 
[Www.pkbulk.blogspot.com]dbms07
[Www.pkbulk.blogspot.com]dbms07[Www.pkbulk.blogspot.com]dbms07
[Www.pkbulk.blogspot.com]dbms07
 
[Www.pkbulk.blogspot.com]dbms06
[Www.pkbulk.blogspot.com]dbms06[Www.pkbulk.blogspot.com]dbms06
[Www.pkbulk.blogspot.com]dbms06
 
[Www.pkbulk.blogspot.com]dbms05
[Www.pkbulk.blogspot.com]dbms05[Www.pkbulk.blogspot.com]dbms05
[Www.pkbulk.blogspot.com]dbms05
 
[Www.pkbulk.blogspot.com]dbms04
[Www.pkbulk.blogspot.com]dbms04[Www.pkbulk.blogspot.com]dbms04
[Www.pkbulk.blogspot.com]dbms04
 
[Www.pkbulk.blogspot.com]dbms03
[Www.pkbulk.blogspot.com]dbms03[Www.pkbulk.blogspot.com]dbms03
[Www.pkbulk.blogspot.com]dbms03
 
[Www.pkbulk.blogspot.com]dbms02
[Www.pkbulk.blogspot.com]dbms02[Www.pkbulk.blogspot.com]dbms02
[Www.pkbulk.blogspot.com]dbms02
 
[Www.pkbulk.blogspot.com]dbms01
[Www.pkbulk.blogspot.com]dbms01[Www.pkbulk.blogspot.com]dbms01
[Www.pkbulk.blogspot.com]dbms01
 
[Www.pkbulk.blogspot.com]dbms13
[Www.pkbulk.blogspot.com]dbms13[Www.pkbulk.blogspot.com]dbms13
[Www.pkbulk.blogspot.com]dbms13
 
9. java server faces
9. java server faces9. java server faces
9. java server faces
 
8. java script
8. java script8. java script
8. java script
 
7. struts
7. struts7. struts
7. struts
 

Recently uploaded

Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
KarakKing
 

Recently uploaded (20)

Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 

3. applets

  • 1. IMRAN DAUD FOUNDATION UNIVERSITY INSTITUTE OF MANAGEMENT AND COMPUTER SCIENCES Imran Daud FUIMCS Web Engineering Java Applets
  • 2. Applets  An applet is a Java program that a browser can download and run.  An applet is 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.  Swing provides javax.swing.JApplet.
  • 3. Sample Applet Code  Two steps to turning it in to an Applet  1. Change "extend JFrame" to "extends JApplet" and get rid of the main, you'll have to   import javax.swing.JApplet  public class MyApp extends JApplet {  ...  } // end MyApp   2. Embed the application into the webpage, using html   <html>  <head>  <title> My Applet </title  </head>  <body>  <! this is the applet tag which has attributes, there must be code, width, height>  <applet code = "MyApp.class” width = "300” height = "300”>  <! there can be optional parameters >  <param name="someParamName" value="paramStringValue" >  </applet>  </body>  </html>
  • 4. Applet Life Cycle  loaded -> created -> initialized -> started <=> stopped -> destroyed  The applet maybe stopped because the user has changed focused  JApplet has methods initialized, started, stopped and destroyed phases. They have default behavior that you can over write.  init() - this where you can load the parameter, someParamName, with their String values using getParamter("someParamName"). Note that order is not important.  start() - here you can start things after stopping  stop() - allows you save information before stopping and to use in start()  destroy() - allows you clean up. Note stop will be called first.
  • 5. Applets have restrictions:  Cannot read or write files on the client machine  Cannot run programs on the client machine  Cannot make any computer connections But the Applet can read data files on the Sever
  • 6. Steps to create Applet Projects in Netbeans  Choose File > New Project (Ctrl-Shift-N). Under Categories, select Java.  Choose one of the following:  If you are creating a new applet source file, select Java Class Library under Projects. Click Next.  If you want to import an applet source file, select Java Project with Existing Sources. Click Next. Specify the file's location in the Source Packages Folder text box.  Under Project Name, type HelloApplet. Change the Project Location to any folder on your computer.  Click Finish.
  • 7. Create applet source file  Right-click the HelloApplet project and choose Properties to open the Properties window.  Select the desired Source / Binary Format for the project from source tab.  Right-click the HelloApplet project node in the Projects window and select New > Other (Ctrl-N).  Under Categories, select Java. Under File Types, select Applet.  (for visual design applet select Swing GUI Forms > JApplet Form.)  Give name to applet and click finish.
  • 8. Demo  Init()  Start()  Stop()  Destroy()
  • 9. Setting ground for applet  Set all static parameters in init() function. Like  Setsize(int width, int height)  Setbackgroundcolor()
  • 11. Drawing Shapes  Rectangle  Oval  Etc (consult documentation)
  • 12. Adding Mouse  MouseListener  MouseMotionListener  (Consult API Documentation for function details)
  • 13. Keyboard Input  KeyListener  actionListener  (Consult API Documentatio)
  • 14.  Panel  JTextField  JTextArea  JCombobox  etc
  • 15. Java Layouts  FlowLayout  BorderLayout  GridLayout  BoxLayout  CardLayout  GridBagLayout  GroupLayout  SpringLayout
  • 16. Threads  Thread --- Class  Runnable ---- Interface
  • 17. Class --- Thread  Public Class A extends Thread{  Public void run(){  }  }  A aa= new A();  aa.start();
  • 18. Runnable  Public class A implements Runnable{  Public void run(){  }  }  A aa = new A();  Thread t1 = new Thread(aa);  t1.start();