EXAMPLE PROGRAM 1(APPLETS)

How to run an Applet?

There are two ways to run an applet
  1. By html file.
  2. By appletViewer tool (for testing purpose).
EXAMPLE PROGRAM :

import java.applet.*;
import java.awt.*;

public class HelloWorldApplet extends Applet {
   public void paint (Graphics g) {
      g.drawString ("Hello World", 25, 50);
   }
}
These import statements bring the classes into the scope of our applet class −
  • import java.awt.applet.*;
  • import java.awt.Graphics;

Invoking an Applet


<html>
   <title>The Hello, World Applet</title>
   <hr>
   <applet code = "HelloWorldApplet.class" width = "320" height = "120">
      
   </applet>
   <hr>
</html>

Comments