7.3 Java Applet
7.3 Java Applet
Advantage of Applet
Drawback of Applet
Do You Know
o Who is responsible to manage the life cycle of an applet?
o How to perform animation in applet?
o How to paint like paint brush in applet?
o How to display digital clock in applet?
o How to display analog clock in applet?
o How to communicate two applets?
Hierarchy of Applet
1. Applet is initialized.
2. Applet is started.
3. Applet is painted.
4. Applet is stopped.
5. Applet is destroyed.
java.applet.Applet class
java.awt.Component class
1. By html file.
2. By appletViewer tool (for testing purpose).
Simple example of Applet by html file:
1. //First.java
2. import java.applet.Applet;
3. import java.awt.Graphics;
4. public class First extends Applet{
5.
6. public void paint(Graphics g){
7. g.drawString("welcome",150,150);
8. }
9.
10. }
myapplet.html
1. <html>
2. <body>
3. <applet code="First.class" width="300" height="300">
4. </applet>
5. </body>
6. </html>
Simple example of Applet by appletviewer tool:
1. //First.java
2. import java.applet.Applet;
3. import java.awt.Graphics;
4. public class First extends Applet{
5.
6. public void paint(Graphics g){
7. g.drawString("welcome to applet",150,150);
8. }
9.
10. }
11. /*
12. <applet code="First.class" width="300" height="300">
13. </applet>
14. */
c:\>javac First.java
c:\>appletviewer First.java