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 (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

2. http, html
2. http, html2. http, html
2. http, htmlAnusAhmad
 
6. hibernate
6. hibernate6. hibernate
6. hibernateAnusAhmad
 
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 WSO2
 
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...Ricardo Cañizares Sales
 

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

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

[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 indexingAnusAhmad
 
[Www.pkbulk.blogspot.com]dbms12
[Www.pkbulk.blogspot.com]dbms12[Www.pkbulk.blogspot.com]dbms12
[Www.pkbulk.blogspot.com]dbms12AnusAhmad
 
[Www.pkbulk.blogspot.com]dbms11
[Www.pkbulk.blogspot.com]dbms11[Www.pkbulk.blogspot.com]dbms11
[Www.pkbulk.blogspot.com]dbms11AnusAhmad
 
[Www.pkbulk.blogspot.com]dbms10
[Www.pkbulk.blogspot.com]dbms10[Www.pkbulk.blogspot.com]dbms10
[Www.pkbulk.blogspot.com]dbms10AnusAhmad
 
[Www.pkbulk.blogspot.com]dbms09
[Www.pkbulk.blogspot.com]dbms09[Www.pkbulk.blogspot.com]dbms09
[Www.pkbulk.blogspot.com]dbms09AnusAhmad
 
[Www.pkbulk.blogspot.com]dbms07
[Www.pkbulk.blogspot.com]dbms07[Www.pkbulk.blogspot.com]dbms07
[Www.pkbulk.blogspot.com]dbms07AnusAhmad
 
[Www.pkbulk.blogspot.com]dbms06
[Www.pkbulk.blogspot.com]dbms06[Www.pkbulk.blogspot.com]dbms06
[Www.pkbulk.blogspot.com]dbms06AnusAhmad
 
[Www.pkbulk.blogspot.com]dbms05
[Www.pkbulk.blogspot.com]dbms05[Www.pkbulk.blogspot.com]dbms05
[Www.pkbulk.blogspot.com]dbms05AnusAhmad
 
[Www.pkbulk.blogspot.com]dbms04
[Www.pkbulk.blogspot.com]dbms04[Www.pkbulk.blogspot.com]dbms04
[Www.pkbulk.blogspot.com]dbms04AnusAhmad
 
[Www.pkbulk.blogspot.com]dbms03
[Www.pkbulk.blogspot.com]dbms03[Www.pkbulk.blogspot.com]dbms03
[Www.pkbulk.blogspot.com]dbms03AnusAhmad
 
[Www.pkbulk.blogspot.com]dbms02
[Www.pkbulk.blogspot.com]dbms02[Www.pkbulk.blogspot.com]dbms02
[Www.pkbulk.blogspot.com]dbms02AnusAhmad
 
[Www.pkbulk.blogspot.com]dbms01
[Www.pkbulk.blogspot.com]dbms01[Www.pkbulk.blogspot.com]dbms01
[Www.pkbulk.blogspot.com]dbms01AnusAhmad
 
[Www.pkbulk.blogspot.com]dbms13
[Www.pkbulk.blogspot.com]dbms13[Www.pkbulk.blogspot.com]dbms13
[Www.pkbulk.blogspot.com]dbms13AnusAhmad
 
9. java server faces
9. java server faces9. java server faces
9. java server facesAnusAhmad
 
8. java script
8. java script8. java script
8. java scriptAnusAhmad
 

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

Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementmkooblal
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitolTechU
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
MICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptxMICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptxabhijeetpadhi001
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxEyham Joco
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxDr.Ibrahim Hassaan
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...jaredbarbolino94
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfMr Bounab Samir
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...JhezDiaz1
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxAvyJaneVismanos
 

Recently uploaded (20)

Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of management
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptx
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
MICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptxMICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptx
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptx
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptx
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.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();