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