SlideShare a Scribd company logo
IADCS Diploma Course Applets U Nyein Oo COO/Director(IT) Myanma Computer Co., Ltd
Java Applets  Is a Java program that runs with the help of a web browser All applets are sub-classes of the class ‘Applet’ To create an applet, you need to import the following two packages: java.applet java.awt
Applet Structure An applet defines its structure from four events that take place during the execution   For each event, a method is automatically called   Methods init( )  start( )   stop( )   destroy( )
Applet Structure (Contd…)   Other related methods paint( )  repaint( ) showStatus( )  getAppletInfo( )  Applet methods init(), start(), stop(), destroy(), and paint()  are inherited by an applet Each of these methods is empty by default. Hence, these methods are overridden
Applet Compilation & Execution An applet is compiled using the syntax javac Applet1.java To execute an applet, create an HTML file which uses the applet tag  The applet tag has two attributes Width Height To pass parameters to the applet, use the ‘param’ tag, followed by the ‘value’ tag Applet can be executed using an applet viewer
Example of Applet Import java.applet.Applet; Import java.awt.Graphics; Public class HelloWorldApplet extends Applet{ public void paint(Graphics g){ g.drawString(“Hello World”,50,35); } }
Example of Applet (Cont] <html> <head> <title>Hello World</title> </head> <body> This is an applet<p> <applet codebase=“classes” code=“HelloWorldApplet.class” width=200 height=300></applet> </body> </html>
Difference between an Applet and an Application  Applications run using the Java interpreter, while applets run on any browser that supports Java, or use an ‘AppletViewer’ that is included in the JDK The execution of applications begins with the ‘main()’ method. This is not the case with applets  Applications use the ‘System.out.println()’ to display the output, while applets use the ‘drawstring()’ method to display the output
Security Restrictions on Applets Cannot read or write files on the user’s file system Cannot communicate with an Internet site, but only with one that serves the web page, including the applet Cannot run any programs on the reader’s system Cannot load any programs stored on the user’s system
Applet Life Cycle
Passing parameters to an Applet To pass parameter, the PARAM parameter is to be included in HTML tag Example <applet code = &quot;Mybutton1&quot; width = “100” height = “100”> <PARAM NAME = “Mybutton” value = “Display Dialog”> </applet>
Graphics Class   Provided by AWT package  Provides a collection of methods to draw the following graphical figures Oval  Rectangle Square Circle  Lines Text in different fonts
Graphical Background Methods for getting a graphical background   getGraphics( )  repaint( ) update(Graphics g) paint(Graphics g)
Drawing Strings, Characters and Bytes   Method to draw or print a string on the frame Syntax drawString(String str, int  xCoor, int yCoor); Method to draw or print characters on the frame  Syntax drawChars(char array[ ], int offset, int length, int  xCoor, int yCoor);   Method to draw or print bytes on the frame  Syntax drawBytes(byte array[ ], int offset, int length, int  xCoor, int yCoor);
Drawing Lines and Ovals Method used to draw lines  Syntax drawLine(int x1, int y1, int x2, int y2); Methods used to draw ovals Syntax drawOval(int xCoor, int yCoor, int width, int height); setColor(Color c); fillOval(int xCoor, int yCoor, int width, int height);
Drawing Rectangles and Rounded Rectangles  Methods used to draw rectangles  Syntax drawRect(int xCoor, int yCoor, int width, int height); fillRect(int xCoor, int yCoor, int width, int height); Methods used to draw rounded rectangles Syntax drawRoundRect(int xCoor, int yCoor, int width, int height, int arcWidth, int arcHeight); fillRoundRect (int xCoor, int yCoor, int width, int height, int arcWidth, int arcHeight);
3D Rectangles & Arcs Methods used to draw 3D Rectangles and arcs Syntax  draw3DRect(int xCoord, int yCoord, int width, int height, boolean raised); drawArc(int xCoord, int yCoord, int width, int height, int arcwidth, int archeight); fillArc(int xCoord, int yCoord, int width, int height, int arcwidth, int archeight);
Drawing PolyLines   Methods used to draw a series of lines  Syntax drawPolyline(int xArray[ ], int yArray[ ], int totalPoints); g.setFont(new Font(&quot;Times Roman&quot;, Font.BOLD,15));
Drawing and Filling Polygons Methods to draw and fill polygons   Syntax drawPolygon(int x[ ], int y[ ], int numPoints); fillPolygon(int x[ ], int y[ ], int numPoints);
Color Control Java uses the RGB color model   The range of integer values that a color element can hold   Syntax of the constructor to create custom color   color(int red, int green, int blue); 0-255 Green 0-255 Blue 0-255 Red Range Element
Color Control (Contd…) Table shows RGB values of common colors   255 0 255 Magenta 0 255 255 Yellow 0 200 255 Orange 175 175 255 Pink 0 0 0 Black 64 64 64 Dark Gray 128 128 128 Gray 192 192 192 Light Gray 255 255 255 White Blue Green Red Color
Font Control java.awt package provides the class ‘Font’  Methods of Font class getAllFont( )  getLocalGraphicsEnvironment( )  getFont( ) getFontList( )
Font Control (Contd…) Font constructor takes the following three parameters  Name of the font in string format. This can be obtained from the getFontList( ) method Style of the font. For example, Font.BOLD, Font.PLAIN, Font.ITALIC Size in int form Example Font f1 = new Font(&quot;SansSerif&quot;, Font.ITALIC, 16); g.setFont(f1);
FontMetrics Class Measures various characters present in different fonts Measurement includes the ‘height’, ‘baseline’, ‘ascent’, ‘descent’ and ‘leading’ of a font  It cannot be instantiated as it is an abstract class Methods getFontMetrics(f1)  getHeight( )  getAscent( )  getDescent( )  getLeading( )  getName( )
Paint mode Objects are drawn using the paint mode set Method used to make old and new contents visible on the screen setXORMode(Color c)  Method used t o revert to the overwrite mode setPaintMode( )
Exercise 1 //Applet Exercise One public class Applet1 extends Applet{ int num; public void init(){ num=6; } public void paint(Graphics g){ g.drawString(“Hello to Applets. Chapter “+ num, 70, 80);   showStatus(getAppletInfo());  } public String getAppletInfo() {// user overrides   return “Created by Aptech”; } }
Exercise 2 import java.applet.Applet; import java.awt.*; /*  <applet code = “both” width = 200 height = 100 > </applet> */ public class both extends Applet { Button btn;  public void init() {   btn = new Button(“Click”); } public void paint(Graphics g) { g.drawString(“Applet”, 70, 50 ); } public static void main(String args[]) { both app=new both(); app.init(); System.out.println(“Application Main”); } }

More Related Content

PPTX
PPTX
Applets in java
PPT
Graphics programming in Java
PPT
Java: Java Applets
PPT
Windows Programming with AWT
PPT
Applets
PPT
Applet and graphics programming
PDF
Java Applet and Graphics
Applets in java
Graphics programming in Java
Java: Java Applets
Windows Programming with AWT
Applets
Applet and graphics programming
Java Applet and Graphics

What's hot (20)

PPTX
JAVA AWT
PPTX
java Unit4 chapter1 applets
PPTX
Applet in java
PPTX
PPT
JAVA APPLET BASICS
PDF
Applet in java
PPT
first-applet
PPT
Applet skelton58
PPT
Applet Architecture - Introducing Java Applets
PPTX
java Applet Introduction
PPTX
Java applet - java
PPT
Java applets
PPTX
Applet progming
PDF
Oop suplemnertary september 2019
PPTX
Java applets
PPTX
Java applet
PPTX
Applets in Java
PDF
27 applet programming
JAVA AWT
java Unit4 chapter1 applets
Applet in java
JAVA APPLET BASICS
Applet in java
first-applet
Applet skelton58
Applet Architecture - Introducing Java Applets
java Applet Introduction
Java applet - java
Java applets
Applet progming
Oop suplemnertary september 2019
Java applets
Java applet
Applets in Java
27 applet programming
Ad

Viewers also liked (9)

PDF
Swing
PPTX
Satish training ppt
PPT
Basics of applets.53
DOCX
Srgoc java
PPT
L5 classes, objects, nested and inner class
PPTX
Static keyword ppt
PPTX
Java exception handling
PPT
Applet life cycle
PPT
Java Basics for selenium
Swing
Satish training ppt
Basics of applets.53
Srgoc java
L5 classes, objects, nested and inner class
Static keyword ppt
Java exception handling
Applet life cycle
Java Basics for selenium
Ad

Similar to Client Side Programming with Applet (20)

PPT
Appletsbjhbjiibibibikbibibjibjbibbjb.ppt
PPT
Applets(1)cusdhsiohisdhfshihfsihfohf.ppt
PPTX
L18 applets
PPT
Unit 7 Java
PPT
Applets - lev' 2
PPT
Displaying information within a window.68
PPTX
U5 JAVA.pptx
PPTX
Applet in java new
PPTX
Applet and graphics programming
PPT
Session4 applets
DOCX
Lecture3 oopj
PPT
Intro to JavaFX & Widget FX
DOCX
UNIT-II CP DOC.docx
PPTX
Graphics in C++
PPTX
programming language in c&c++
PPT
Applet ppt for higher understanding education
ODP
Ppt of c vs c#
PPTX
Chapter1.pptx
PPT
ma project
PPTX
Input and Output In C Language
Appletsbjhbjiibibibikbibibjibjbibbjb.ppt
Applets(1)cusdhsiohisdhfshihfsihfohf.ppt
L18 applets
Unit 7 Java
Applets - lev' 2
Displaying information within a window.68
U5 JAVA.pptx
Applet in java new
Applet and graphics programming
Session4 applets
Lecture3 oopj
Intro to JavaFX & Widget FX
UNIT-II CP DOC.docx
Graphics in C++
programming language in c&c++
Applet ppt for higher understanding education
Ppt of c vs c#
Chapter1.pptx
ma project
Input and Output In C Language

More from backdoor (20)

PPT
Java Database Connectivity
PPT
Distributed Programming using RMI
PPT
Programming Server side with Sevlet
PPT
Distributed Programming using RMI
PPT
Java Network Programming
PPT
Windows Programming with Swing
PPT
Multithreading
PPT
Object and Classes in Java
PPT
IO and serialization
PPT
Exception Handling
PPT
Java Intro
PPT
Object Oriented Programming with Java
PPT
AWT Program output
PPT
Net Man
PPT
Data Security
PPT
Ne Course Part One
PPT
Ne Course Part Two
PPT
Net Sec
PDF
Security Policy Checklist
PPT
Bcis Csm Chapter Three
Java Database Connectivity
Distributed Programming using RMI
Programming Server side with Sevlet
Distributed Programming using RMI
Java Network Programming
Windows Programming with Swing
Multithreading
Object and Classes in Java
IO and serialization
Exception Handling
Java Intro
Object Oriented Programming with Java
AWT Program output
Net Man
Data Security
Ne Course Part One
Ne Course Part Two
Net Sec
Security Policy Checklist
Bcis Csm Chapter Three

Recently uploaded (20)

PPTX
MYSQL Presentation for SQL database connectivity
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Empathic Computing: Creating Shared Understanding
PDF
HCSP-Presales-Campus Network Planning and Design V1.0 Training Material-Witho...
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Transforming Manufacturing operations through Intelligent Integrations
PDF
Advanced Soft Computing BINUS July 2025.pdf
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Electronic commerce courselecture one. Pdf
PDF
GDG Cloud Iasi [PUBLIC] Florian Blaga - Unveiling the Evolution of Cybersecur...
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
cuic standard and advanced reporting.pdf
PPTX
Telecom Fraud Prevention Guide | Hyperlink InfoSystem
PDF
madgavkar20181017ppt McKinsey Presentation.pdf
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
MYSQL Presentation for SQL database connectivity
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
The Rise and Fall of 3GPP – Time for a Sabbatical?
Chapter 3 Spatial Domain Image Processing.pdf
Empathic Computing: Creating Shared Understanding
HCSP-Presales-Campus Network Planning and Design V1.0 Training Material-Witho...
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Transforming Manufacturing operations through Intelligent Integrations
Advanced Soft Computing BINUS July 2025.pdf
Spectral efficient network and resource selection model in 5G networks
Electronic commerce courselecture one. Pdf
GDG Cloud Iasi [PUBLIC] Florian Blaga - Unveiling the Evolution of Cybersecur...
Per capita expenditure prediction using model stacking based on satellite ima...
Dropbox Q2 2025 Financial Results & Investor Presentation
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
cuic standard and advanced reporting.pdf
Telecom Fraud Prevention Guide | Hyperlink InfoSystem
madgavkar20181017ppt McKinsey Presentation.pdf
20250228 LYD VKU AI Blended-Learning.pptx

Client Side Programming with Applet

  • 1. IADCS Diploma Course Applets U Nyein Oo COO/Director(IT) Myanma Computer Co., Ltd
  • 2. Java Applets Is a Java program that runs with the help of a web browser All applets are sub-classes of the class ‘Applet’ To create an applet, you need to import the following two packages: java.applet java.awt
  • 3. Applet Structure An applet defines its structure from four events that take place during the execution For each event, a method is automatically called Methods init( ) start( ) stop( ) destroy( )
  • 4. Applet Structure (Contd…) Other related methods paint( ) repaint( ) showStatus( ) getAppletInfo( ) Applet methods init(), start(), stop(), destroy(), and paint() are inherited by an applet Each of these methods is empty by default. Hence, these methods are overridden
  • 5. Applet Compilation & Execution An applet is compiled using the syntax javac Applet1.java To execute an applet, create an HTML file which uses the applet tag The applet tag has two attributes Width Height To pass parameters to the applet, use the ‘param’ tag, followed by the ‘value’ tag Applet can be executed using an applet viewer
  • 6. Example of Applet Import java.applet.Applet; Import java.awt.Graphics; Public class HelloWorldApplet extends Applet{ public void paint(Graphics g){ g.drawString(“Hello World”,50,35); } }
  • 7. Example of Applet (Cont] <html> <head> <title>Hello World</title> </head> <body> This is an applet<p> <applet codebase=“classes” code=“HelloWorldApplet.class” width=200 height=300></applet> </body> </html>
  • 8. Difference between an Applet and an Application Applications run using the Java interpreter, while applets run on any browser that supports Java, or use an ‘AppletViewer’ that is included in the JDK The execution of applications begins with the ‘main()’ method. This is not the case with applets Applications use the ‘System.out.println()’ to display the output, while applets use the ‘drawstring()’ method to display the output
  • 9. Security Restrictions on Applets Cannot read or write files on the user’s file system Cannot communicate with an Internet site, but only with one that serves the web page, including the applet Cannot run any programs on the reader’s system Cannot load any programs stored on the user’s system
  • 11. Passing parameters to an Applet To pass parameter, the PARAM parameter is to be included in HTML tag Example <applet code = &quot;Mybutton1&quot; width = “100” height = “100”> <PARAM NAME = “Mybutton” value = “Display Dialog”> </applet>
  • 12. Graphics Class Provided by AWT package Provides a collection of methods to draw the following graphical figures Oval Rectangle Square Circle Lines Text in different fonts
  • 13. Graphical Background Methods for getting a graphical background getGraphics( ) repaint( ) update(Graphics g) paint(Graphics g)
  • 14. Drawing Strings, Characters and Bytes Method to draw or print a string on the frame Syntax drawString(String str, int xCoor, int yCoor); Method to draw or print characters on the frame Syntax drawChars(char array[ ], int offset, int length, int xCoor, int yCoor); Method to draw or print bytes on the frame Syntax drawBytes(byte array[ ], int offset, int length, int xCoor, int yCoor);
  • 15. Drawing Lines and Ovals Method used to draw lines Syntax drawLine(int x1, int y1, int x2, int y2); Methods used to draw ovals Syntax drawOval(int xCoor, int yCoor, int width, int height); setColor(Color c); fillOval(int xCoor, int yCoor, int width, int height);
  • 16. Drawing Rectangles and Rounded Rectangles Methods used to draw rectangles Syntax drawRect(int xCoor, int yCoor, int width, int height); fillRect(int xCoor, int yCoor, int width, int height); Methods used to draw rounded rectangles Syntax drawRoundRect(int xCoor, int yCoor, int width, int height, int arcWidth, int arcHeight); fillRoundRect (int xCoor, int yCoor, int width, int height, int arcWidth, int arcHeight);
  • 17. 3D Rectangles & Arcs Methods used to draw 3D Rectangles and arcs Syntax draw3DRect(int xCoord, int yCoord, int width, int height, boolean raised); drawArc(int xCoord, int yCoord, int width, int height, int arcwidth, int archeight); fillArc(int xCoord, int yCoord, int width, int height, int arcwidth, int archeight);
  • 18. Drawing PolyLines Methods used to draw a series of lines Syntax drawPolyline(int xArray[ ], int yArray[ ], int totalPoints); g.setFont(new Font(&quot;Times Roman&quot;, Font.BOLD,15));
  • 19. Drawing and Filling Polygons Methods to draw and fill polygons Syntax drawPolygon(int x[ ], int y[ ], int numPoints); fillPolygon(int x[ ], int y[ ], int numPoints);
  • 20. Color Control Java uses the RGB color model The range of integer values that a color element can hold Syntax of the constructor to create custom color   color(int red, int green, int blue); 0-255 Green 0-255 Blue 0-255 Red Range Element
  • 21. Color Control (Contd…) Table shows RGB values of common colors 255 0 255 Magenta 0 255 255 Yellow 0 200 255 Orange 175 175 255 Pink 0 0 0 Black 64 64 64 Dark Gray 128 128 128 Gray 192 192 192 Light Gray 255 255 255 White Blue Green Red Color
  • 22. Font Control java.awt package provides the class ‘Font’ Methods of Font class getAllFont( ) getLocalGraphicsEnvironment( ) getFont( ) getFontList( )
  • 23. Font Control (Contd…) Font constructor takes the following three parameters Name of the font in string format. This can be obtained from the getFontList( ) method Style of the font. For example, Font.BOLD, Font.PLAIN, Font.ITALIC Size in int form Example Font f1 = new Font(&quot;SansSerif&quot;, Font.ITALIC, 16); g.setFont(f1);
  • 24. FontMetrics Class Measures various characters present in different fonts Measurement includes the ‘height’, ‘baseline’, ‘ascent’, ‘descent’ and ‘leading’ of a font It cannot be instantiated as it is an abstract class Methods getFontMetrics(f1) getHeight( ) getAscent( ) getDescent( ) getLeading( ) getName( )
  • 25. Paint mode Objects are drawn using the paint mode set Method used to make old and new contents visible on the screen setXORMode(Color c) Method used t o revert to the overwrite mode setPaintMode( )
  • 26. Exercise 1 //Applet Exercise One public class Applet1 extends Applet{ int num; public void init(){ num=6; } public void paint(Graphics g){ g.drawString(“Hello to Applets. Chapter “+ num, 70, 80); showStatus(getAppletInfo()); } public String getAppletInfo() {// user overrides return “Created by Aptech”; } }
  • 27. Exercise 2 import java.applet.Applet; import java.awt.*; /* <applet code = “both” width = 200 height = 100 > </applet> */ public class both extends Applet { Button btn; public void init() { btn = new Button(“Click”); } public void paint(Graphics g) { g.drawString(“Applet”, 70, 50 ); } public static void main(String args[]) { both app=new both(); app.init(); System.out.println(“Application Main”); } }