2. Contents
Introducing an Applet.
The genealogy of Japplet.
Description with example.
Method of creating a webpage.
3. Introducing Applets
Applets are simple java programs can be
executed on browsers.
Aplet classes should be imported.
Applet may not have ‘main’ method.
Eg :-
IE (Internet Explorer)
Firefox
Chrome
4. The genealogy of JApplet
java.lang.Object
|
+----java.awt.Component
|
+----java.awt.Container
|
+----java.awt.Panel
|
+----java.applet.Applet
|
+----javax.swing.JApplet
5. Method of creating an Applet
import java.applet.*;
import java.awt.graphics;
public class HelloWorld extends Applet
{
public void paint(Graphics g)
{
g.drawRect(40,40,200,100);
g.drawString("Hello World!", 80, 60);
}}
Hello World
6. This program should be saved as
HelloWorld.java
The user need to create a html file to execute
Applet program
7. <html>
<head>
</head>
<body>
<applet code=“HelloWorld.class” width=“400”
height=“400”>
</applet>
</body>
</html>
This Applet.html can be execued using
appletviewer on command prompt.
8. C:> d:
D:> cd appletviewer applet.htm
Then it will be appear like this
Hello World
9. drawOval - Oval / circle
drawRect - Rectangle / Square
drawString – String / Text
FillOval - Oval with black fill color
FillRect - Rectangle with black fill color