SlideShare una empresa de Scribd logo
1 de 13
Simple applet program




                        1
Objectives

On completion of this period, you will be able to
  learn
• Simple Applet program




                                                    2
Recap

In the last class we have studied about the
  Basics of Applet
• There exist two types of Java programs
  • Java Application which is a console based program
  • Applet which is a web enabled Java program for
    Internet applications purpose




                                                        3
Simple Applet
The following program shows how to write a simple
  applet

import java.awt.*;
import java.applet.*;
public class SimpleApplet extends Applet {
  public void paint(Graphics g) {
    g.drawString(“Hello Applet", 20, 20);
  }
}


                                                    4
Simple Applet      contd..
• It has two import statements namely
  • import java.awt.*;
  • import java.applet.*;
• First statement imports the Abstract Windowing
  Toolkit (AWT) classes
• Applets interact with the user through the AWT,
  not through the console-based I/O classes.
• Second import statement imports the Applet
  class from the applet package



                                                5
Simple Applet          contd..

• Every applet that you create must be a subclass
  of Applet
• The next line in the program declares the class
  SimpleApplet
• This class must be declared as public, because
  it will be accessed by code that is outside the
  program




                                                 6
Simple Applet         contd..

• Inside SimpleApplet, paint( ) is defined
• This method is defined by the AWT and must be
  overridden by the applet
• paint( ) is called each time that the applet must
  redisplay its output




                                                  7
Simple Applet              contd..

• Inside paint( ) is a call to drawString( ), which is
  a member of the Graphics class
• General form is:
   • void drawString(String message, int x, int y)
      where, message is the string to be output
        beginning at x, y




                                                         8
Simple Applet          contd..

• In window, the upper-left corner is at location
  0,0
• Call to drawString( ) in the applet causes the
  message
• “Hello Applet” to be displayed at location
  20,20




                                                    9
Summary

   In this class, you have learnt
• We have learned how to write a simple applet
  program
• We learned the importance of each statement
  in the Applet program




                                                 10
Frequently Asked Questions

• Write an applet program which draws a simple
  string called “Hello Applet”




                                                 11
Quiz

1. Applets interact with the user through ----
   1. AWT
   2. console
   3. command line
   4. none




                                                 12
Quiz

2. Applet class must be declared as public
   – True
   – False




                                             13

Más contenido relacionado

La actualidad más candente

La actualidad más candente (18)

Applet and graphics programming
Applet and graphics programmingApplet and graphics programming
Applet and graphics programming
 
Graphics programming in Java
Graphics programming in JavaGraphics programming in Java
Graphics programming in Java
 
Client Side Programming with Applet
Client Side Programming with AppletClient Side Programming with Applet
Client Side Programming with Applet
 
01review
01review01review
01review
 
4 programming-using-java intro-tojava20102011
4 programming-using-java intro-tojava201020114 programming-using-java intro-tojava20102011
4 programming-using-java intro-tojava20102011
 
Java Tutorial
Java TutorialJava Tutorial
Java Tutorial
 
Applet programming
Applet programming Applet programming
Applet programming
 
Basics of applets.53
Basics of applets.53Basics of applets.53
Basics of applets.53
 
Introduction to Java programming - Java tutorial for beginners to teach Java ...
Introduction to Java programming - Java tutorial for beginners to teach Java ...Introduction to Java programming - Java tutorial for beginners to teach Java ...
Introduction to Java programming - Java tutorial for beginners to teach Java ...
 
Introduction to java Programming
Introduction to java ProgrammingIntroduction to java Programming
Introduction to java Programming
 
Introduction to computer science
Introduction to computer scienceIntroduction to computer science
Introduction to computer science
 
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 tutorial PPT
Java tutorial PPTJava tutorial PPT
Java tutorial PPT
 
Java features
Java featuresJava features
Java features
 
BRUG - Hello, Scala
BRUG - Hello, ScalaBRUG - Hello, Scala
BRUG - Hello, Scala
 
Java basics notes
Java basics notesJava basics notes
Java basics notes
 
Appletjava
AppletjavaAppletjava
Appletjava
 
Java tutorials
Java tutorialsJava tutorials
Java tutorials
 

Similar a Simple Applet Program Explained

Similar a Simple Applet Program Explained (20)

Java chapter 7
Java chapter 7Java chapter 7
Java chapter 7
 
Applet programming
Applet programming Applet programming
Applet programming
 
Applets
AppletsApplets
Applets
 
java Applet Introduction
java Applet Introductionjava Applet Introduction
java Applet Introduction
 
Applet in java new
Applet in java newApplet in java new
Applet in java new
 
Applet execution
Applet execution Applet execution
Applet execution
 
Creating applets.60
Creating applets.60Creating applets.60
Creating applets.60
 
Applet in java
Applet in javaApplet in java
Applet in java
 
Applet skelton58
Applet skelton58Applet skelton58
Applet skelton58
 
Java Applets
Java AppletsJava Applets
Java Applets
 
Applet1 (1).pptx
Applet1 (1).pptxApplet1 (1).pptx
Applet1 (1).pptx
 
Applets 101-fa06
Applets 101-fa06Applets 101-fa06
Applets 101-fa06
 
Applets
AppletsApplets
Applets
 
Applets
AppletsApplets
Applets
 
Basic of Applet
Basic of AppletBasic of Applet
Basic of Applet
 
Applet programming1
Applet programming1Applet programming1
Applet programming1
 
Till applet skeleton
Till applet skeletonTill applet skeleton
Till applet skeleton
 
Slide8appletv2 091028110313-phpapp01
Slide8appletv2 091028110313-phpapp01Slide8appletv2 091028110313-phpapp01
Slide8appletv2 091028110313-phpapp01
 
L18 applets
L18 appletsL18 applets
L18 applets
 
Applet (1)
Applet (1)Applet (1)
Applet (1)
 

Más 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
 

Simple Applet Program Explained

  • 2. Objectives On completion of this period, you will be able to learn • Simple Applet program 2
  • 3. Recap In the last class we have studied about the Basics of Applet • There exist two types of Java programs • Java Application which is a console based program • Applet which is a web enabled Java program for Internet applications purpose 3
  • 4. Simple Applet The following program shows how to write a simple applet import java.awt.*; import java.applet.*; public class SimpleApplet extends Applet { public void paint(Graphics g) { g.drawString(“Hello Applet", 20, 20); } } 4
  • 5. Simple Applet contd.. • It has two import statements namely • import java.awt.*; • import java.applet.*; • First statement imports the Abstract Windowing Toolkit (AWT) classes • Applets interact with the user through the AWT, not through the console-based I/O classes. • Second import statement imports the Applet class from the applet package 5
  • 6. Simple Applet contd.. • Every applet that you create must be a subclass of Applet • The next line in the program declares the class SimpleApplet • This class must be declared as public, because it will be accessed by code that is outside the program 6
  • 7. Simple Applet contd.. • Inside SimpleApplet, paint( ) is defined • This method is defined by the AWT and must be overridden by the applet • paint( ) is called each time that the applet must redisplay its output 7
  • 8. Simple Applet contd.. • Inside paint( ) is a call to drawString( ), which is a member of the Graphics class • General form is: • void drawString(String message, int x, int y) where, message is the string to be output beginning at x, y 8
  • 9. Simple Applet contd.. • In window, the upper-left corner is at location 0,0 • Call to drawString( ) in the applet causes the message • “Hello Applet” to be displayed at location 20,20 9
  • 10. Summary In this class, you have learnt • We have learned how to write a simple applet program • We learned the importance of each statement in the Applet program 10
  • 11. Frequently Asked Questions • Write an applet program which draws a simple string called “Hello Applet” 11
  • 12. Quiz 1. Applets interact with the user through ---- 1. AWT 2. console 3. command line 4. none 12
  • 13. Quiz 2. Applet class must be declared as public – True – False 13