SlideShare une entreprise Scribd logo
1  sur  13
Creating simple example applets




                                  1
Objectives

On completion of this period, you would be able to
  learn
• Creating simple applets




                                                     2
Recap

In the previous classes , you have studied about
• Order of applet initialization
• Order of applet termination




                                                   3
Creating simple applet

We will go through some example
applet




                                  4
1.Write an applet to draw and fill rectangle
     import java.awt.*;
     import java.applet.*;
     /*
     <applet code = MyApplet width= 200 height=150>
     </applet>*/
     public class MyApplet extends Applet {
             public void paint(Graphics g) {
                     g.drawRect(50,50,100,100);
                     g.fillRect(200,200,300,300);
        //draw filled in rectangle of default color
             }
     }
                                                      5
2. Write an applet to draw a string
import java.awt.*;
import java.applet.*;
/*
<applet code = SimpleApplet width = 400 height = 400 >
</applet>
*/
public class SimpleApplet extends Applet {
   public void paint(Graphics g) {
           g.drawString ("Welcome to the world of applet
                  programming", 20, 20);
   }
}


                                                       6
3. Program to test all methods of applet
import java.awt.*;
import java.applet.*;
/*
<applet code = Allmethods width = 400 height= 400>
</applet>
*/
public class Allmethods extends Applet {
 String s1, s2, s3, s4;
  public void init() {
    s1= "message from init method"; }
 public void start() {
   s2= "message from start method"; }
 public void stop() {
   s3= " message from stop method"; }


                                                     7
3. Program to test all methods of applet
                                                           contd..
public void destroy() {
   s4= " message from destroying"; }
 public void paint(Graphics g) {
g.drawString("Demo for testing all methods of applet", 20,40);
 if(s1!=null)
    g.drawString(s1,20,80);
if(s2!=null)
 g.drawString(s2,20,100);
 if(s3!=null)
g.drawString(s3,20,120);
 if(s4!=null)
g.drawString(s4,20,140);
 }
}



                                                                     8
4. Applet program to change the foreground
          and back ground colors
     import java.awt.*;
     import java.applet.*;
     import java.awt.Graphics;
     import java.awt.Color;
      /*
     <applet code="Sample" width=300 height=50>
     </applet>     */
 public class Sample extends Applet{
 String msg;
 // set the foreground and background colors.
 public void init() {
 setBackground(Color.cyan);
 setForeground(Color.red);
 msg = "Inside init( ) --"; }                     9
Applet program to change the foreground and
             back ground colors     contd..
    // Initialize the string to be displayed.
        public void start() {
          msg += " Inside start( ) --";
        }
    // Display msg in applet window.
        public void paint(Graphics g) {
          msg += " Inside paint( ).";
          g.drawString(msg, 10, 30);
        }
    }




                                                10
Summary

• We have written several applet programs
• Covering the different aspects of applets




                                              11
Quiz

1. Where is the JVM available to run an applet
    when an applet is downloaded from an
    internet into our local machine where java
    was not installed
a) Local
b) Remote




                                                 12
Frequently Asked Questions

• Write applet program to draw the following
  diagram




                                               13

Contenu connexe

Tendances

Java applets
Java appletsJava applets
Java applets
lopjuan
 
Windows Programming with AWT
Windows Programming with AWTWindows Programming with AWT
Windows Programming with AWT
backdoor
 

Tendances (20)

Applet
AppletApplet
Applet
 
Java: Java Applets
Java: Java AppletsJava: Java Applets
Java: Java Applets
 
Java applet - java
Java applet - javaJava applet - java
Java applet - java
 
Java Applet and Graphics
Java Applet and GraphicsJava Applet and Graphics
Java Applet and Graphics
 
Java applets
Java appletsJava applets
Java applets
 
Applet in java
Applet in javaApplet in java
Applet in java
 
java Applet Introduction
java Applet Introductionjava Applet Introduction
java Applet Introduction
 
Applet programming
Applet programming Applet programming
Applet programming
 
JAVA APPLETS
JAVA APPLETSJAVA APPLETS
JAVA APPLETS
 
Applet progming
Applet progmingApplet progming
Applet progming
 
Applet Architecture - Introducing Java Applets
Applet Architecture - Introducing Java AppletsApplet Architecture - Introducing Java Applets
Applet Architecture - Introducing Java Applets
 
first-applet
first-appletfirst-applet
first-applet
 
Java applets
Java appletsJava applets
Java applets
 
Applets in Java
Applets in JavaApplets in Java
Applets in Java
 
java Unit4 chapter1 applets
java Unit4 chapter1 appletsjava Unit4 chapter1 applets
java Unit4 chapter1 applets
 
27 applet programming
27  applet programming27  applet programming
27 applet programming
 
Java applets
Java appletsJava applets
Java applets
 
Programming Fundamentals lecture 5
Programming Fundamentals lecture 5Programming Fundamentals lecture 5
Programming Fundamentals lecture 5
 
Native cross-platform mobile apps with C# and Xamarin.Forms
Native cross-platform mobile apps with C# and Xamarin.FormsNative cross-platform mobile apps with C# and Xamarin.Forms
Native cross-platform mobile apps with C# and Xamarin.Forms
 
Windows Programming with AWT
Windows Programming with AWTWindows Programming with AWT
Windows Programming with AWT
 

Similaire à Creating applets.60

Applets 101-fa06
Applets 101-fa06Applets 101-fa06
Applets 101-fa06
nrayan
 
Slide8appletv2 091028110313-phpapp01
Slide8appletv2 091028110313-phpapp01Slide8appletv2 091028110313-phpapp01
Slide8appletv2 091028110313-phpapp01
Abhishek Khune
 

Similaire à Creating applets.60 (20)

Applet in java new
Applet in java newApplet in java new
Applet in java new
 
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
 
Basic of Applet
Basic of AppletBasic of Applet
Basic of Applet
 
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
 
Unit 7 Java
Unit 7 JavaUnit 7 Java
Unit 7 Java
 
Applets 101-fa06
Applets 101-fa06Applets 101-fa06
Applets 101-fa06
 
Java applet
Java appletJava applet
Java applet
 
Applet-Presentation-object-oriented-programming.pptx
Applet-Presentation-object-oriented-programming.pptxApplet-Presentation-object-oriented-programming.pptx
Applet-Presentation-object-oriented-programming.pptx
 
APPLET.pptx
APPLET.pptxAPPLET.pptx
APPLET.pptx
 
Java chapter 7
Java chapter 7Java chapter 7
Java chapter 7
 
Slide8appletv2 091028110313-phpapp01
Slide8appletv2 091028110313-phpapp01Slide8appletv2 091028110313-phpapp01
Slide8appletv2 091028110313-phpapp01
 
java programming - applets
java programming - appletsjava programming - applets
java programming - applets
 
171-33B - Java Programming-Building Applets.ppt
171-33B - Java Programming-Building Applets.ppt171-33B - Java Programming-Building Applets.ppt
171-33B - Java Programming-Building Applets.ppt
 
Applets
AppletsApplets
Applets
 
Introduction to Java Applets
Introduction to Java AppletsIntroduction to Java Applets
Introduction to Java Applets
 
L18 applets
L18 appletsL18 applets
L18 applets
 
Oops
OopsOops
Oops
 
Applets - lev' 2
Applets - lev' 2Applets - lev' 2
Applets - lev' 2
 
applet.pptx
applet.pptxapplet.pptx
applet.pptx
 

Plus de myrajendra (20)

Fundamentals
FundamentalsFundamentals
Fundamentals
 
Data type
Data typeData type
Data type
 
Hibernate example1
Hibernate example1Hibernate example1
Hibernate example1
 
Jdbc workflow
Jdbc workflowJdbc workflow
Jdbc workflow
 
2 jdbc drivers
2 jdbc drivers2 jdbc drivers
2 jdbc drivers
 
3 jdbc api
3 jdbc api3 jdbc api
3 jdbc api
 
4 jdbc step1
4 jdbc step14 jdbc step1
4 jdbc step1
 
Dao example
Dao exampleDao example
Dao example
 
Sessionex1
Sessionex1Sessionex1
Sessionex1
 
Internal
InternalInternal
Internal
 
3. elements
3. elements3. elements
3. elements
 
2. attributes
2. attributes2. attributes
2. attributes
 
1 introduction to html
1 introduction to html1 introduction to html
1 introduction to html
 
Headings
HeadingsHeadings
Headings
 
Forms
FormsForms
Forms
 
Css
CssCss
Css
 
Views
ViewsViews
Views
 
Views
ViewsViews
Views
 
Views
ViewsViews
Views
 
Starting jdbc
Starting jdbcStarting jdbc
Starting jdbc
 

Creating applets.60

  • 2. Objectives On completion of this period, you would be able to learn • Creating simple applets 2
  • 3. Recap In the previous classes , you have studied about • Order of applet initialization • Order of applet termination 3
  • 4. Creating simple applet We will go through some example applet 4
  • 5. 1.Write an applet to draw and fill rectangle import java.awt.*; import java.applet.*; /* <applet code = MyApplet width= 200 height=150> </applet>*/ public class MyApplet extends Applet { public void paint(Graphics g) { g.drawRect(50,50,100,100); g.fillRect(200,200,300,300); //draw filled in rectangle of default color } } 5
  • 6. 2. Write an applet to draw a string import java.awt.*; import java.applet.*; /* <applet code = SimpleApplet width = 400 height = 400 > </applet> */ public class SimpleApplet extends Applet { public void paint(Graphics g) { g.drawString ("Welcome to the world of applet programming", 20, 20); } } 6
  • 7. 3. Program to test all methods of applet import java.awt.*; import java.applet.*; /* <applet code = Allmethods width = 400 height= 400> </applet> */ public class Allmethods extends Applet { String s1, s2, s3, s4; public void init() { s1= "message from init method"; } public void start() { s2= "message from start method"; } public void stop() { s3= " message from stop method"; } 7
  • 8. 3. Program to test all methods of applet contd.. public void destroy() { s4= " message from destroying"; } public void paint(Graphics g) { g.drawString("Demo for testing all methods of applet", 20,40); if(s1!=null) g.drawString(s1,20,80); if(s2!=null) g.drawString(s2,20,100); if(s3!=null) g.drawString(s3,20,120); if(s4!=null) g.drawString(s4,20,140); } } 8
  • 9. 4. Applet program to change the foreground and back ground colors import java.awt.*; import java.applet.*; import java.awt.Graphics; import java.awt.Color; /* <applet code="Sample" width=300 height=50> </applet> */ public class Sample extends Applet{ String msg; // set the foreground and background colors. public void init() { setBackground(Color.cyan); setForeground(Color.red); msg = "Inside init( ) --"; } 9
  • 10. Applet program to change the foreground and back ground colors contd.. // Initialize the string to be displayed. public void start() { msg += " Inside start( ) --"; } // Display msg in applet window. public void paint(Graphics g) { msg += " Inside paint( )."; g.drawString(msg, 10, 30); } } 10
  • 11. Summary • We have written several applet programs • Covering the different aspects of applets 11
  • 12. Quiz 1. Where is the JVM available to run an applet when an applet is downloaded from an internet into our local machine where java was not installed a) Local b) Remote 12
  • 13. Frequently Asked Questions • Write applet program to draw the following diagram 13