Hello World program using Applet in Java

  1. import java.applet.Applet;  
  2. import java.awt.*;  
  3. import java.awt.event.*;  
  4.   
  5. public class HelloWorldApplet extends Applet{  
  6.     public static void main(String[] args){  
  7.         Frame frame = new Frame("Roseindia.net");  
  8.         frame.setSize(400,200);  
  9.         Applet app = new HelloWorldApplet();  
  10.         frame.add(app);  
  11.         frame.setVisible(true);  
  12.         frame.addWindowListener(new WindowAdapter(){  
  13.             public void windowClosing(WindowEvent e){  
  14.                 System.exit(0);  
  15.             }  
  16.         });  
  17.     }  
  18.     public void paint(Graphics g){  
  19.         g.drawString("Hello World!",200,100);  
  20.     }